public VMUserCreate() { User = new User(); User.IsActive = true; ConfirmPassword = String.Empty; }
//[Bind(Include = "Id,Name,Username,Password,EmailAdress,IsActive")] public ActionResult Edit(User User) { if (ModelState.IsValid) { //var loremIpsum = ""; //if (UOW.UserRepository.Get().Where(p => p.Id == 58).ToList().First().IsActive == true) //{ // loremIpsum = ""; //} ////isto ta a dar if (UOW.UserRepository.Get(c => c.Name == User.Name && c.Id != User.Id).ToList().Count() > 0) { TempData["Alert"] = AlertHelper.GenerateAlert(Models.Widgets.NotificationType.ERROR, "Already exists one user with this name."); return View(User); } if (UOW.UserRepository.Get(c => c.Username == User.Username && c.Id != User.Id).ToList().Count() > 0) { TempData["Alert"] = AlertHelper.GenerateAlert(Models.Widgets.NotificationType.ERROR, "Already exists one user with this username."); return View(User); } if (UOW.UserRepository.Get(c => c.EmailAdress == User.EmailAdress && c.Id != User.Id).ToList().Count() > 0) { TempData["Alert"] = AlertHelper.GenerateAlert(Models.Widgets.NotificationType.ERROR, "Already exists one user with this email address."); return View(User); } var BDUpdated = UOW.UserRepository.GetByID(User.Id); User.UpdatedAt = DateTime.Now; User.UpdatedBy = 58; UOW.Context.Entry(BDUpdated).CurrentValues.SetValues(User); UOW.Context.Entry(BDUpdated).State = EntityState.Modified; // UOW.UserRepository.Update(BDUpdated); UOW.Save(); TempData["Alert"] = AlertHelper.GenerateAlert(Models.Widgets.NotificationType.SUCCESS, "User updated successfully."); //UOW.Save(); return RedirectToAction("Index"); } return View(User); }