There are some website that provide Demos for their premium Html/css/javascript themes while we can see and copy the source code without paying anything. Why? Why don't they only provide a snapshot of the website theme to prevent any illegal copy?
Alex Dunlop
Posts
-
Why do some websites provide Demo for their premium html themes while the codes can be seen using inspection tool in chrome? -
Choosing a proper database for mobile messenger appMy main problem is concurrent database read/write capability. I'll delete "seen" messages every month. I think Sqlite is not good for this project. What about SQL Server? Or Mongodb?
-
Choosing a proper database for mobile messenger appI'm wokring on a mobile messenger app using Flutter. I'd write backend code in Node.js. My app will have a list of users and each user can send request to other users to get paired with them. Each user can reject/accept other users' requests. If two users get paired, they can send message to each other or make a voice/video call. All messages transfered between users will be registered on the database for further analysis or detecting any criminal materials or misuses. I'd have about 2000 users, meaning the maximum online users are about 2000 people. The overal nature of the backend model is relational. I need to choose a proper database for this app. My options are MongoDb and Sqlite. Which one is good for this project? Can Sqlite handle this project with that amount of users?
-
Entity Framework Code First - two Foreign Keys from same tableI have the following models:
public class User
{
[Key]
public int UserId { get; set; }
public string Name { get; set; }
public string LastName { get; set; }
public string? ImageUrl { get; set; }//Navigation properties public virtual List Requests { get; set; } public virtual List Messages { get; set; } }
public class Request
{
[Key]
public int RequestId { get; set; }
public DateTime RequestTime { get; set; } = DateTime.Now;
public bool? AcceptStatus { get; set; }//Navigation properties public User TargetUserRef { get; set; } public User SenderUserRef { get; set; } }
I want the Request table to have two foreign keys. I tried to use the following fluent API:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity()
.HasOne(m => m.SenderUserRef)
.WithMany(t => t.Requests)
.HasForeignKey(m => m.RequestId)
.OnDelete(DeleteBehavior.Restrict);modelBuilder.Entity() .HasOne(m => m.TargetUserRef) .WithMany(t => t.Requests) .HasForeignKey(m => m.RequestId) .OnDelete(DeleteBehavior.Restrict); }
When I try to create migration, the following error is shown:
Quote:
Cannot create a relationship between 'User.Requests' and 'Request.TargetUserRef' because a relationship already exists between 'User.Requests' and 'Request.SenderUserRef'. Navigations can only participate in a single relationship. If you want to override an existing relationship call 'Ignore' on the navigation 'Request.TargetUserRef' first in 'OnModelCreating'.
How can I solve this problem?
-
How to secure Python application using license key?I want to secure my python app using an online license key. Consider the following simple example:
import requests
def license():
# The list with all keys.
keys = requests.get("http://yourlink.com/licensekeys.txt").text
# keys = ["key1", "key2", "key3"]# License key from user. keyfromuser = "mykey" for key in keys.splitlines(): if key == keyfromuser: # Code when key match. return # Code if the key don't match. exit()
license()
Anybody can open my code in notepad and make some changes to disable the license key requirement. What is the best strategy to implement license approach to make it harder to beginner and intermediate level programmers to reverse engineer my app?
-
How to convert tagged text into html formatted text?I'm using CKEditor in my Angular project. I save my text, for example, as the following in the database:
My Header 1
My Header 2
My Header 3
My long text.
I want to retrieve the formatted version of it and then show it to the user. How can I do this in typescript?
-
Is it possible to share SQL Server database between WPF application and Ionic applicationI want to develop a WPF application and then develop an Ionic application for mobile. I'm planning to create an API for an Ionic application that uses the same database. Is it feasible? Should I create an API and use it for both WPF and Ionic applications?
-
A question about CreatedAtAction() methodHi, What does
CreatedAtAction(...)
method do in the following code (a part of an API code)?
//Add single card
[HttpPost]
[Route("id:guid")]
public async Task AddCard([FromBody] Card card)
{
card.Id = Guid.NewGuid();
await context.AddAsync(card);
await context.SaveChangesAsync();
return CreatedAtAction(nameof(GetCard), card.Id, card);
} -
A question about routing attributeHi, What does [Route("id:guid")] mean in the following code? (This code is a part of an API)
[HttpGet]
[Route("id:guid")]
[ActionName("GetCard")]
public async Task GetCard([FromRoute]Guid id)
{
var card = await context.Cards.FirstOrDefaultAsync(x => x.Id == id);
if(card != null)
{
return Ok(card);
}
return NotFound("Card not found");
} -
Which one of the following codes has better performance in ASP.NET Core?I use repository pattern in my project. Which coding strategy is better? 1)
var messages = _messageRepository.GetAllMessages().Where(x => x.senderId == myId).ToList();
//Filtering is done in Repository
var messages = _messageRepository.GetAllMessages(myId).ToList(); -
How is SignalR aware of userID while EF Core Identity has been deployed as login system?I'm using EF Core Identity as register/login system in my project. I tried to use signalR to push notification when a new message is send to a user. I have a form with two inputs, one for user who will receive the message and the other for the main message text. The message information is stored in the database and a notification is send to the client. I used the following codes: Adding signalR service to **program.cs**:
builder.Services.AddSignalR();
.
.
app.MapHub("/msgHub");Code for **Hub**:
public class MessageHub : Hub
{
private readonly IUserRepository _userRepository;
private readonly ICostCenterRepository _costcenterRepository;public MessageHub(IUserRepository userRepository, ICostCenterRepository costcenterRepository) { \_userRepository = userRepository; \_costcenterRepository = costcenterRepository; } public async Task SendMessage(string costCenter) { string userId = \_userRepository.GetUserIdByCostCenter(costCenter).ToString(); await Clients.User(userId).SendAsync("ReceiveMessage"); } }
Code for **message.js**:
var connection = new signalR.HubConnectionBuilder().withUrl("/msgHub").withAutomaticReconnect().build();
connection.start();
document.getElementById("sendBtn").addEventListener("click", function () {
var costCenter = $("#cost-center").val();
connection.invoke("SendMessage", costCenter).catch(function (err) {
return console.error(err.tostring());
});
});Script in the view:
connection.on("ReceiveMessage", function () { location.reload(); }); connection.start().catch(function (err) { return console.error(err.tostring()); });
Controller for sending message:
public JsonResult Send(string inputMessageText, string costCenter)
{
int CurrentUserId = Convert.ToInt32(HttpContext.Session.GetString("userId"));
int receiverId = _userRepository.GetUserIdByCostCenter(costCenter);if (!ModelState.IsValid) { return Json(new { success = false}); } else { var newMessage = new Message()
-
How to fill Foreign Key in a relational database when creating a new row?I added the following code to PM model:
public int userId { get; set; }
and changed the navigation property to the following code:
//Navigation property
[ForeignKey("userId ")]
public virtual AppUser user { get; set; } -
How to fill Foreign Key in a relational database when creating a new row?I have a model as follows:
[Key]
public int pmId { get; set; }
[Required]
public int pmNumber { get; set; }
[Required]
[MaxLength(50)]
public string costCenter { get; set; }
[Required]
[MaxLength(15)]
public string serviceType { get; set; }
[Required]
[MaxLength(50)]
public string destination { get; set; }
[Required]
[MaxLength(50)]
public string workCenter { get; set; }
[Required]
public DateTime creationDate { get; set; }
[Display]
[Required]
public DateTime startDate { get; set; }
[Required]
public DateTime endDate { get; set; }
[Required]
[MaxLength(100)]
public string mainFileName { get; set; }
public DateTime? returnDate { get; set; }
public string? status { get; set; }
[MaxLength(100)]
public string? fileName { get; set; }
public int? uploader { get; set; }
public bool? isDownloaded { get; set; } = false;//Navigation property
public virtual AppUser user { get; set; }
//Navigation property
public PM()
{}
The Foreign Key is id which is Primary Key of the EF Core Identity table. In a form, I need to insert a new row in PM table. I can fill all necessary columns using the following code:
var inputElements = new PM()
{
pmNumber = Convert.ToInt32(adminModel.pmNumber),
costCenter = adminModel.costCenter,
serviceType = adminModel.serviceType,
destination = adminModel.destination,
workCenter = adminModel.workCenter,
creationDate = DateTime.Now,
startDate = DateTime.Now,
endDate = DateTime.Now,
mainFileName = newFileName
};But, because of relational nature of my tables, I need to specify userId when creating a new row in PM table. How can I set Foreign Key? I can detect userId using Session object but I don't know how to insert it in the table.
-
Does creating relational database using code-first approach have any advantage in ASP.NET?Presuming we use C# codes for doing all CRUD operations, is it worth to use relational database?
-
Using two models in a single viewI need to use two models in a single view. The models are "AppUser" and "PM". I created a View model as follows:
public class PageViewModel
{
public PM PmModel { get; set; }
public AppUser UserModel { get; set; }
}and used following code in the view:
@model IEnumerable
The problem is that When I run the application, the following error is shown:
Quote:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1[CustomizedIdentity.Models.PM]', but this ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IEnumerable`1[CustomizedIdentity.ViewModel.PageViewModel]'.
How can I fix this error?
-
An unhandled exception occurred while processing the constructor in ASP.NET Core MVCThanks, Solved.
-
An unhandled exception occurred while processing the constructor in ASP.NET Core MVCI use the following code for dependency injection of Register/Login controller. The problem is that I cannot use Repository pattern I have created previously.
private readonly UserManager _userManager;
private readonly SignInManager _signInManager;
private readonly IUserRepository _userRepository;public HomeController(UserManager userManager, SignInManager signInManager, IUserRepository userRepository) { \_userManager = userManager; \_signInManager = signInManager; \_userRepository = userRepository; }
When I run the code, the following error is occured:
Quote:
InvalidOperationException: Unable to resolve service for type 'CustomizedIdentity.Repositories.IUserRepository' while attempting to activate 'CustomizedIdentity.Controllers.HomeController'.
-
How to access to all the information of a signed-In user stored in User table in ASP.NET Core?I've created a custom User table using EF Core Identity (registration). Many of these custom columns are True/False values that are filled when the registration of that specific user is done. I have also created a login system that the user enters their username and password to sign in. Now, I want to get access to those information stored in the database for the user signed in successfully and use session to send them to the page. Please help me. Dependancy injection for Home Controller:
private readonly UserManager _userManager;
private readonly SignInManager _signInManager;public HomeController(UserManager userManager, SignInManager signInManager) { \_userManager = userManager; \_signInManager = signInManager; }
Code for Register:
[HttpPost]
public async Task Register(RegisterViewModel registerModel)
{
DateTime currentDate = DateTime.Now;
if (ModelState.IsValid)
{
var user = new AppUser()
{
UserName = registerModel.userName,
department = registerModel.department,
creationDate = currentDate,
isAdmin = registerModel.isAdmin,
isManager = registerModel.isManager,
isActive = registerModel.isActive,
canEdit = registerModel.canEdit,
canDelete = registerModel.canDelete,
canSendMessage = registerModel.canSendMessage,
canSeeNotification = registerModel.canSeeNotification
};
var result = await _userManager.CreateAsync(user, registerModel.password);
if (result.Succeeded)
{
await _signInManager.SignInAsync(user, isPersistent: false);
return RedirectToAction("Privacy", "Home");
}
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error.Description);
}
ModelState.AddModelError(string.Empty, "Invalid Register Attempt");
}
return View();
}Code for Login:
[HttpPost]
public async Task Index(LoginViewModel user)
{
if (ModelState.IsValid)
{ -
How to integrate Identity and business layer in an ASP.NET Core project?My project has a database with multiple tables. One table is Users that has a key called userId. Other tables are Messages, Notifications, and Files that have relationship with the User table through userId. I can create User table (a customized Identity system) using EF Core Identity. User table is created using a class inherited from IdentityDbContext class while other tables are created using a class inherited from DbContext class. My problem is that how can I create those other tables while keeping their relation. Please help me.
-
Creating Register and Login system in MVC Core projectHi, I have made my model and created all necessary migrations using EntityFramework and finally, created sql server database (Code First). You can see my database diagram corresponding to my model: Capture — ImgBB[^] As you see, I have defined all necessary columns for User. My register system needs username, password, department, isAdmin, IsActive, canEdit, canDelete, canSendMessage, canSeeNotificaion which are provided through text fields and checkboxes. I have designed my own Login/Register page previously (using HTML, CSS, Js). I created a _LoginLayout in my ASP.NET Core project. Now, I need to create database connection and all necessary codes for this system. How can I do that? Do I need to use Identity scaffolding and create new DbContext (While I have defined my User class and created the related tables in database)?