public static BloodDonorViewModel UpdateBloodDonor(BloodDonorViewModel donor) { var db = new bloodbankDbContext(); BloodDonor oldDonor = db.BloodDonors.Where(e => e.RegNo == donor.RegNo).FirstOrDefault(); User oldUser = db.Users.Where(e => e.BloodDonorId == oldDonor.Id).FirstOrDefault(); oldDonor.Name = donor.Name; oldDonor.NickName = donor.NickName; oldDonor.Mobile = donor.Mobile; oldDonor.EmergencyContact = donor.EmergencyContact; oldDonor.Comment = donor.Comment; oldDonor.Division = donor.Division; oldDonor.LastDonatedDate = donor.LastDonatedDate; oldDonor.BloodGroup = donor.BloodGroup; oldDonor.Email = donor.Email; if (donor.Password != null) { oldUser.Password = PasswordHash.Hash(donor.Password); } db.Entry(oldDonor).State = System.Data.Entity.EntityState.Modified; db.Entry(oldUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(donor); }
public static int CreateUser(UserViewModel user) { var db = new bloodbankDbContext(); User create_user = new User { UserName = user.UserName, Password = PasswordHash.Hash(user.Password), Email = user.Email, PasswordSalt = Guid.NewGuid().ToString("N").Substring(0, 8), ForgetPasswordToken = Guid.NewGuid().ToString("N").Substring(0, 20), Token = Guid.NewGuid().ToString("N").Substring(0, 6), SecuritySitemap = Guid.NewGuid().ToString("N").Substring(0, 12), FailedLoginAttempt = 0, LastLoginAt = DateTime.Now, MobileNumber = "", BlockedUser = false, FullName = user.UserName, Image = "", UserRole = "user", BloodDonorId = user.BloodDonorId }; db.Users.Add(create_user); int result = db.SaveChanges(); return(result); }
public static DonationPost AddDonationPost(DonationPost model) { var db = new bloodbankDbContext(); db.DonationPosts.Add(model); db.SaveChanges(); return(model); }
public static BloodDonor ApproveDonor(int id) { var db = new bloodbankDbContext(); var blooddonor = new BloodDonor(); BloodDonor bloodDonor = db.BloodDonors.Find(id); if (bloodDonor == null) { return(null); } bloodDonor.IsVerified = true; db.Entry(bloodDonor).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(bloodDonor); }
public static BloodDonor LastDonationDateUpdate(int id, DateTime date) { var db = new bloodbankDbContext(); var blooddonor = new BloodDonor(); BloodDonor bloodDonor = db.BloodDonors.Find(id); if (bloodDonor == null) { return(null); } bloodDonor.LastDonatedDate = date; bloodDonor.HasDonated = true; db.Entry(bloodDonor).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(bloodDonor); }
public static int AddPlasmaDonor(PlasmaDonorViewModel model) { var db = new bloodbankDbContext(); PlasmaDonor plasmaDonor = new PlasmaDonor(); User user = db.Users.Where(e => e.UserName == model.RegNo).FirstOrDefault(); BloodDonor donor = db.BloodDonors.Where(e => e.Id == user.BloodDonorId).FirstOrDefault(); plasmaDonor.AffectedDate = model.AffectedDate; plasmaDonor.BloodDonorId = donor.Id; plasmaDonor.RecoveryDate = model.RecoveryDate; plasmaDonor.HasDonated = false; plasmaDonor.IsVerified = false; db.PlasmaDonors.Add(plasmaDonor); db.SaveChanges(); return(plasmaDonor.Id); }
public static int RegisterBloodDonor(BloodDonorViewModel model) { var db = new bloodbankDbContext(); var blooddonor = new BloodDonor(); blooddonor.Name = model.Name; blooddonor.Email = model.Email; blooddonor.Mobile = model.Mobile; blooddonor.IsVerified = false; blooddonor.LastDonatedDate = model.LastDonatedDate ?? new DateTime(2000, 1, 1); blooddonor.BloodGroup = model.BloodGroup; blooddonor.Division = model.Division; blooddonor.NickName = model.NickName; blooddonor.RegNo = model.RegNo; blooddonor.EmergencyContact = model.EmergencyContact; blooddonor.Comment = model.Comment; blooddonor.Longitude = 0; blooddonor.Latitude = 0; blooddonor.IsVerified = false; blooddonor.HasDonated = model.LastDonatedDate == null ? false : true; db.BloodDonors.Add(blooddonor); db.SaveChanges(); UserViewModel user = new UserViewModel { Password = model.Password, UserName = model.Username, Email = model.Email ?? "", BloodDonorId = blooddonor.Id }; int result = UserDataAccess.CreateUser(user); return(blooddonor.Id); }
public static int AutoGenerateUser() { var db = new bloodbankDbContext(); List <BloodDonor> bloodDonors = db.BloodDonors.ToList(); int result = 0; foreach (BloodDonor bloodDonor in bloodDonors) { bool exist = db.Users.Where(e => e.BloodDonorId == bloodDonor.Id).Count() > 0; if (!exist) { User user = new User { UserName = bloodDonor.RegNo, Password = PasswordHash.Hash(bloodDonor.RegNo), Email = bloodDonor.Email ?? "", PasswordSalt = Guid.NewGuid().ToString("N").Substring(0, 8), ForgetPasswordToken = Guid.NewGuid().ToString("N").Substring(0, 20), Token = Guid.NewGuid().ToString("N").Substring(0, 6), SecuritySitemap = Guid.NewGuid().ToString("N").Substring(0, 12), FailedLoginAttempt = 0, LastLoginAt = DateTime.Now, MobileNumber = "", BlockedUser = false, FullName = bloodDonor.Name, Image = "", UserRole = "user", BloodDonorId = bloodDonor.Id }; db.Users.Add(user); } result = db.SaveChanges(); } return(result); }