public ActionResult EditUser(UserProfile_form model) { // Admtszh admuser = repository.Admtszh.Where(p => p.AdmtszhId.Equals(WebSecurity.CurrentUserId)).SingleOrDefault(); // uk_profile uk = repository.uk_profile.Where(p => p.id.Equals(admuser.id_uk)).SingleOrDefault(); webpages_UsersInRoles userrole = new webpages_UsersInRoles(); string[] ir = Roles.GetRolesForUser(model.login); if (ir.Length > 0) { Roles.RemoveUserFromRoles(model.login, ir); } if (model.Role != null) { Roles.AddUserToRoles(model.login, model.Role); } UserProfile profile = new UserProfile(model); repository.SaveUserRole(userrole); if (ModelState.IsValid) { repository.SaveUser(profile); TempData["message"] = string.Format("Изменения странице \"{0}\" были сохранены", model.login); } IEnumerable <uk_profile> list_uk = repository.uk_profile.OrderBy(p => p.id); ViewData["uk_profile"] = from n in list_uk select new SelectListItem { Text = n.Name, Value = n.id.ToString() }; IEnumerable <uk_adress> list_adr = repository.uk_adress.Where(p => p.id.Equals(model.Adress)); ViewData["uk_adress"] = from adr in list_adr select new SelectListItem { Text = adr.City.ToString() + ", " + adr.Street.ToString() + ", " + adr.House, Value = adr.id.ToString() }; //присвоить роль пользователю model.Role = Roles.GetRolesForUser(model.login); return(Json(model)); }
//public ActionResult EditUser(int id = 0) //{ // UserProfile profile = repository.UserProfile.Where(i => i.UserId == id).SingleOrDefault(); // IEnumerable<uk_profile> list_uk = repository.uk_profile.OrderBy(p => p.id); // ViewData["uk_profile"] = from n in list_uk // select new SelectListItem { Text = n.Name, Value = n.id.ToString() }; // IEnumerable<uk_adress> list_adr = repository.uk_adress.Where(p =>p.id_uk.Equals(profile.id_uk)).OrderBy(p => p.id); // ViewData["uk_adress"] = from adr in list_adr // select new SelectListItem { Text = adr.City.ToString() + ", "+adr.Street.ToString() + ", " + adr.House, Value = adr.id.ToString() }; // //присвоить роль пользователю // UserProfile_form model = new UserProfile_form(profile); // model.Role = Roles.GetRolesForUser(profile.login); // return View(model); //} public ActionResult EditUser(string login = "") { UserProfile profile = repository.UserProfile.Where(i => i.login.Equals(login)).SingleOrDefault(); IEnumerable <uk_profile> list_uk = repository.uk_profile.OrderBy(p => p.id); ViewData["uk_profile"] = from n in list_uk select new SelectListItem { Text = n.Name, Value = n.id.ToString() }; IEnumerable <uk_adress> list_adr; if (profile != null) { list_adr = repository.uk_adress.Where(p => p.id_uk.Equals(profile.id_uk)).OrderBy(p => p.id); ViewData["uk_adress"] = from adr in list_adr select new SelectListItem { Text = adr.City.ToString() + ", " + adr.Street.ToString() + ", " + adr.House, Value = adr.id.ToString() }; } else { List <uk_adress> list = new List <uk_adress>(); ViewData["uk_adress"] = from adr in list.ToArray() select new SelectListItem { Text = adr.City.ToString() + ", " + adr.Street.ToString() + ", " + adr.House, Value = adr.id.ToString() }; } if (profile != null) { UserProfile_form model = new UserProfile_form(profile); model.Role = Roles.GetRolesForUser(profile.login); return(View(model)); } else //присвоить роль пользователю { UserProfile_form model = new UserProfile_form(); model.UserId = Convert.ToInt32(Membership.GetUser(login).ProviderUserKey); return(View(model)); } }
public ActionResult EditUser(int id = 0) { // Admtszh admuser = repository.Admtszh.Where(p => p.AdmtszhId.Equals(WebSecurity.CurrentUserId)).SingleOrDefault(); // uk_profile uk = repository.uk_profile.Where(p => p.id.Equals(admuser.id_uk)).SingleOrDefault(); UserProfile profile = repository.UserProfile.Where(i => i.UserId == id).SingleOrDefault(); if (id > 0) { string[] ir = Roles.GetUsersInRole(profile.login); foreach (string r in ir) { if (r == "Admin") { return(Json("Error", "Запрещено! Данный пользователь имеет более высокии привилегии")); } } IEnumerable <uk_profile> list_uk = repository.uk_profile.OrderBy(p => p.id); ViewData["uk_profile"] = from n in list_uk select new SelectListItem { Text = n.Name, Value = n.id.ToString() }; IEnumerable <uk_adress> list_adr = repository.uk_adress.Where(p => p.id_uk.Equals(profile.id_uk)).OrderBy(p => p.id); ViewData["uk_adress"] = from adr in list_adr select new SelectListItem { Text = adr.City.ToString() + ", " + adr.Street.ToString() + ", " + adr.House, Value = adr.id.ToString() }; //присвоить роль пользователю UserProfile_form model = new UserProfile_form(profile); model.Role = Roles.GetRolesForUser(profile.login); return(Json(model, JsonRequestBehavior.AllowGet)); } else { return(View(new UserProfile_form())); } }