public ActionResult AddUser() { var User = new UserViewModel() { AvailLimits = db.Limit.ToList(), allRoles = db.UserRole.ToList(), currRoles = new List<UserRole>(), SelectedRoles = new int[0] }; // ViewBag.limits = db.Limit.Select(el => new { id = el.Id, values = string.Format("{0}/{1}/{2}", el.Fitnes, el.Proezd, el.CultureEvents) }); return View(User); }
public ActionResult AddUser(UserViewModel user) { if (ModelState.IsValid) { var usr = new User() { FullName = user.FullName, Email = user.Email, Login = user.Login, Limit = db.Limit.Find(user.SelectedLimitId), Roles = user.SelectedRoles.Select(el => db.UserRole.Find(el)).ToList() }; db.Users.Add(usr); db.SaveChanges(); FixBid(user.realProezdLimit, user.realFitnesLimit, user.realCultureEvent, usr); return RedirectToAction("Index"); } return View(new UserViewModel() { AvailLimits = db.Limit.ToList() }); }
public ActionResult Edit(int id) { var usr = db.Users.Find(id); if (usr == null) return HttpNotFound(); var allLimits = db.Limit.ToList(); var Roles = db.UserRole.ToList(); var usrVm = new UserViewModel() { FullName = usr.FullName, Email = usr.Email, Limit = usr.Limit, Login = usr.Login, SelectedLimitId = usr.Limit != null ? usr.Limit.Id : allLimits.First().Id, AvailLimits = allLimits, allRoles = Roles, currRoles = usr.Roles, SelectedRoles = usr.Roles.Select(el => el.RoleId).ToArray() }; return View(usrVm); }
public ActionResult Edit(UserViewModel user) { var usr = db.Users.Find(user.id); usr.Roles.Clear(); usr.Roles = user.SelectedRoles.Select(el => db.UserRole.Find(el)).ToList(); usr.Limit = db.Limit.Find(user.SelectedLimitId); usr.FullName = user.FullName; usr.Email = user.Email; db.Entry(usr).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); }