public ActionResult Edit([Bind(Include = "ARE_IDE_AREA,ARE_DES_NAME,ARE_FH_CREATED")] Area area) { if (ModelState.IsValid) { db.Entry(area).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(area)); }
void SeedUsers(AuthenticationDB context) { if (!isInitDb) { return; } var pwd = new PasswordHasher(); string hashed = pwd.HashPassword("admin@123"); User admin = new User() { UserName = "******", Email = "*****@*****.**", EmailConfirmed = true, PhoneNumber = "+84936124031", PhoneNumberConfirmed = true, SecurityStamp = Guid.NewGuid().ToString("D"), PasswordHash = hashed }; if (!context.Users.Any(u => u.UserName == admin.UserName)) { var userStore = new UserStore <User>(context); var result = userStore.CreateAsync(admin); foreach (string role in roles) { userStore.AddToRoleAsync(admin, role); } } context.SaveChanges(); }
public override bool ChangePassword(string username, string oldPassword, string newPassword) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword)) { return(false); } using (AuthenticationDB dbContext = new AuthenticationDB()) { var user = (from us in dbContext.Users where string.Compare(username, us.Username, StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(oldPassword, us.Password, StringComparison.OrdinalIgnoreCase) == 0 && us.IsActive == true select us).FirstOrDefault(); if (user == null) { return(false); } user.Password = newPassword; dbContext.SaveChanges(); return(true); } }
public void EditCoWorker(int id, string pas) { using (var db = new AuthenticationDB()) { db.Usrs.FirstOrDefault(x => x.UserId == id).UserPassword = pas; db.SaveChanges(); } }
public void Create(User model) { using (AuthenticationDB db = new AuthenticationDB()) { db.Users.Add(model); db.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { Role role = db.Roles.Find(id); db.Roles.Remove(role); db.SaveChanges(); return(RedirectToAction("Index")); }
public void DeleteCoWorker(int id) { using (var db = new AuthenticationDB()) { db.InWs.RemoveRange(db.InWs.Where(u => u.RefUser.UserId == id)); db.Pharms.RemoveRange(db.Pharms.Where(u => u.RefUser.UserId == id)); db.Usrs.RemoveRange(db.Usrs.Where(u => u.UserId == id)); db.SaveChanges(); } }
public ActionResult DeleteMedicine(int id) { using (var db = new AuthenticationDB()) { db.Medicines.Remove(db.Medicines.FirstOrDefault(m => m.MedicineID == id)); db.SaveChanges(); } return(RedirectToAction("Medicines")); }
public void DeletePatient(int patient) { using (var db = new AuthenticationDB()) { // ReSharper disable once AssignNullToNotNullAttribute db.Patients.Remove(db.Patients.FirstOrDefault(p => (p.PatientID == patient) && (p.Doctor.RefUser.UserId == ((OrdPrincipal)HttpContext.User).UserID))); db.SaveChanges(); } }
//public override void AddUserToRole(string username, string roleName) //{ // throw new NotImplementedException(); //} public override void CreateRole(string roleName) { Role role = new Role(); role.RoleName = roleName; // throw new NotImplementedException(); using (AuthenticationDB db = new AuthenticationDB()) { db.Roles.Add(role); db.SaveChanges(); } }
public bool Create(Role model) { if (model != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Roles.Add(model); return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public Boolean Create(Invoice model) { if (model != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Invoices.Add(model); return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public void AddMedicine(int medicineId, int currentPatient) { using (var db = new AuthenticationDB()) { db.Patients .FirstOrDefault(p => (p.PatientID == currentPatient) & (p.Doctor.RefUser.UserId == ((OrdPrincipal)HttpContext.User).UserID)) ?.Medicines .Add(db.Medicines.FirstOrDefault(m => m.MedicineID == medicineId)); db.SaveChanges(); } }
public void DeleteMedicine(int patient, int medicine) { using (var db = new AuthenticationDB()) { db.Patients .FirstOrDefault(p => (p.PatientID == patient) && (p.Doctor.RefUser.UserId == ((OrdPrincipal)HttpContext.User).UserID)) ?.Medicines .Remove(db.Medicines.FirstOrDefault(m => m.MedicineID == medicine)); db.SaveChanges(); } }
public ActionResult Registration(RegistrationView registrationView) { bool statusRegistration = false; string messageRegistration = string.Empty; if (ModelState.IsValid) { // Email Verification string userName = Membership.GetUserNameByEmail(registrationView.Email); if (!string.IsNullOrEmpty(userName)) { ModelState.AddModelError("Warning Email", "Sorry: Email already Exists"); return(View(registrationView)); } User user = null; //Save User Data using (AuthenticationDB dbContext = new AuthenticationDB()) { user = new User() { USR_DES_NAME = registrationView.Username, USR_DES_FIRST_NAME = registrationView.FirstName, USR_DES_LAST_NAME = registrationView.LastName, USR_DES_EMAIL = registrationView.Email, USR_IDE_AREA = registrationView.Area, USR_DES_POSITION = registrationView.Position, USR_DES_PHONE = registrationView.Phone, USR_DES_PASSWORD = registrationView.Password, USR_FH_CREATED = DateTime.Now, USR_LAST_LOGIN = DateTime.Now, ActivationCode = Guid.NewGuid(), }; dbContext.Users.Add(user); dbContext.SaveChanges(); } //Verification Email //VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString()); VerificationEmail(registrationView.Email, user.ActivationCode.ToString()); messageRegistration = "Your account has been created successfully. ^_^"; statusRegistration = true; } else { messageRegistration = "Something Wrong!"; } ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(View(registrationView)); }
public Boolean Update(Role Role) { if (Role != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Roles.Attach(Role); db.Entry(Role).Property(ob => ob.TUSR_DES_TYPE).IsModified = true; return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public Boolean Update(Area area) { if (area != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Areas.Attach(area); db.Entry(area).Property(ob => ob.ARE_DES_NAME).IsModified = true; return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public Boolean Update(StatusAprov StatusAprov) { if (StatusAprov != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.StatusAprovs.Attach(StatusAprov); db.Entry(StatusAprov).Property(ob => ob.STA_DES_STATUS).IsModified = true; return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public Boolean Update(User User) { if (User != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Entry(User).State = EntityState.Modified; db.SaveChanges(); } return(true); } return(false); }
public Boolean Update(AccountingAccount accountingAccount) { if (accountingAccount != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.AccountingAccounts.Attach(accountingAccount); db.Entry(accountingAccount).Property(ob => ob.ACC_DES_ACCOUNT).IsModified = true; return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public Boolean Update(Invoice model) { if (model != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Invoices.Attach(model); //TODO: Ver cuales son los que se tendrán que estar actualizando //db.Entry(model).Property(ob => ob.STA_DES_STATUS).IsModified = true; return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public ActionResult EditMedicine(int id, double?price) { using (var db = new AuthenticationDB()) { if (!price.HasValue || price.Value <= 0) { return(RedirectToAction("Medicines")); } db.Medicines.FirstOrDefault(m => m.MedicineID == id).Price = price.Value; db.SaveChanges(); } return(RedirectToAction("Medicines")); }
public ActionResult CoWorkers(CoWorkersVM VM) // add co-worker { if (!ModelState.IsValid) { return(RedirectToAction("CoWorkers")); } string type; using (var db = new AuthenticationDB()) { if (db.Usrs.Any(x => x.UserName == VM.NewCoWorker.UserName)) { return(RedirectToAction("CoWorkers")); } type = VM.NewCoWorker.Type; db.Usrs.Add(new User { UserName = VM.NewCoWorker.UserName, FirstName = VM.NewCoWorker.FirstName, LastName = VM.NewCoWorker.LastName, Roles = db.Rls.Where(r => r.RoleName == type).ToList(), UserPassword = VM.NewCoWorker.Password, }); db.SaveChanges(); } using (var db = new AuthenticationDB()) { if (type == "Insurance worker") { db.InWs.Add(new InW { Doc = db.Usrs.FirstOrDefault(u => u.UserId == ((OrdPrincipal)User).UserID), InsuranceName = VM.NewCoWorker.Employer, RefUser = db.Usrs.FirstOrDefault(u => u.UserName == VM.NewCoWorker.UserName), }); } else if (type == "Pharmacist") { db.Pharms.Add(new Pharm { Doc = db.Usrs.FirstOrDefault(u => u.UserId == ((OrdPrincipal)User).UserID), Pharmacy = VM.NewCoWorker.Employer, RefUser = db.Usrs.FirstOrDefault(u => u.UserName == VM.NewCoWorker.UserName), }); } db.SaveChanges(); } return(RedirectToAction("CoWorkers")); }
public ActionResult Registration(RegistrationView registrationView) { bool statusRegistration = false; string messageRegistration = string.Empty; if (ModelState.IsValid) { // Email Verification string userName = Membership.GetUserNameByEmail(registrationView.Email); if (!string.IsNullOrEmpty(userName)) { ModelState.AddModelError("Warning Email", "Ese Email ya esta registrado"); return(View(registrationView)); } //Save User Data using (AuthenticationDB dbContext = new AuthenticationDB()) { var user = new User() { Username = registrationView.Username, FirstName = registrationView.FirstName, LastName = registrationView.LastName, Email = registrationView.Email, Password = ComputeSha256Hash(registrationView.Password), //Password = registrationView.Password, IsActive = true, //ActivationCode = Guid.NewGuid(), //ActivationCode = Guid.NewGuid(), }; dbContext.Users.Add(user); dbContext.SaveChanges(); } //Verification Email //VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString()); messageRegistration = "Cuenta creada satisfactoriamente"; statusRegistration = true; } else { messageRegistration = "Problema creando cuenta!"; } ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(View(registrationView)); }
public Boolean Delete(string id) { User User = GetOne(id); if (User != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Users.Remove(User); db.SaveChanges(); } return(true); } return(false); }
public ActionResult Registration(RegistrationView registrationView) { bool statusRegistration = false; string messageRegistration = string.Empty; if (ModelState.IsValid) { // Email Verification string userName = Membership.GetUserNameByEmail(registrationView.Email); if (!string.IsNullOrEmpty(userName)) { ModelState.AddModelError("Warning Email", "Sorry: Email already Exists"); return(View(registrationView)); } //Save User Data using (AuthenticationDB dbContext = new AuthenticationDB()) { var user = new User() { Username = registrationView.Username, FirstName = registrationView.FirstName, LastName = registrationView.LastName, Email = registrationView.Email, Password = registrationView.Password, ActivationCode = Guid.NewGuid(), }; dbContext.Users.Add(user); dbContext.SaveChanges(); registrationView.ActivationCode = user.ActivationCode; } //Verification Email VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString()); messageRegistration = "Your account has been created successfully. ^_^"; statusRegistration = true; } else { messageRegistration = "Something Wrong!"; } ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(View(registrationView)); }
public Boolean Update(Request model) { if (model != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Requests.Attach(model); db.Entry(model).Property(ob => ob.REQ_DES_TYPE_GASTO).IsModified = true; db.Entry(model).Property(ob => ob.REQ_DES_CONCEPT).IsModified = true; db.Entry(model).Property(ob => ob.REQ_DES_QUANTITY).IsModified = true; db.Entry(model).Property(ob => ob.REQ_DES_OBSERVATIONS).IsModified = true; return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public Boolean Update(Budget model) { if (model != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Budgets.Attach(model); db.Entry(model).Property(ob => ob.BUD_IDE_ACCOUNT).IsModified = true; db.Entry(model).Property(ob => ob.BUD_IDE_AREA).IsModified = true; db.Entry(model).Property(ob => ob.BUD_DES_QUANTITY).IsModified = true; db.Entry(model).Property(ob => ob.BUD_DES_PERIOD).IsModified = true; return((db.SaveChanges() > 0) ? true : false); } } return(false); }
public Boolean Delete(string id) { if (id != null) { Invoice model = GetOne(id); if (model != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Invoices.Attach(model); db.Entry(model).State = System.Data.Entity.EntityState.Deleted; return((db.SaveChanges() > 0) ? true : false);; } } } return(false); }
public Boolean Delete(int?id) { if (id != null) { Role Role = GetOne(id); if (Role != null) { using (AuthenticationDB db = new AuthenticationDB()) { db.Roles.Attach(Role); db.Entry(Role).State = System.Data.Entity.EntityState.Deleted; return((db.SaveChanges() > 0) ? true : false);; } } } return(false); }