public Result <User> GetUseerByUserNamePassword(string UserName, string Password) { Result <User> result = new Result <User>(); try { var password = HashConvertor.GetHashString(Password); var username = UserName.ToLower(); result.Data = db.Users.FirstOrDefault(a => a.UserName == username && a.Password == password); if (result.Data == null) { result.Success = false; result.Message = "Username or password is not correct !!";; } else { result.Success = true; } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity <Device>() .HasKey(c => new { c.MarkCode, c.SerialNumber }); modelBuilder.Entity <DataCollection>().HasOne(p => p.Device).WithMany(a => a.DataCollections) .HasForeignKey(p => new { p.MarkCode, p.SerialNumber }); modelBuilder.Entity <DataCollection>() .HasIndex(b => b.DateCreated); #region Default data var AdminId = ConstantsVariables.AdminstratorId; var now = DateTime.Now; modelBuilder.Entity <User>().HasData( new User { Id = AdminId, FirstName = "admin", LastName = "admin", BirthDate = now, DateCreated = now, DateModified = now, UserModified = AdminId, UserCreated = AdminId, IsDeleted = false, UserName = "******", Password = HashConvertor.GetHashString("admin"), Picture = "" }); for (int i = 65; i <= 75; i++) { modelBuilder.Entity <Mark>().HasData( new Mark { Code = Convert.ToChar(i).ToString(), Name = "Mark " + (i - 64), DateCreated = now, DateModified = now, UserModified = AdminId, UserCreated = AdminId, IsDeleted = false }); modelBuilder.Entity <Device>().HasData( new Device { MarkCode = Convert.ToChar(i).ToString(), SerialNumber = 123456, Port = "8091", IpAddress = "127.0.0.1", DateCreated = now, DateModified = now, UserModified = AdminId, UserCreated = AdminId, IsDeleted = false }); modelBuilder.Entity <Device>().HasData( new Device { MarkCode = Convert.ToChar(i).ToString(), SerialNumber = 123457, Port = "8091", IpAddress = "127.0.0.1", DateCreated = now, DateModified = now, UserModified = AdminId, UserCreated = AdminId, IsDeleted = false }); } #endregion }