public static Boolean AdminLocaleModify(ModifyLocaleViewModel cursub) //partial, including name,areaid,localeId { // check name unique under a specific area // modify name OR modify parent area OR both var curarea = (from f in db.Areas where f.Name.ToLower() == cursub.SelectArea.ToLower() select f).FirstOrDefault(); var temp = (from b in db.Locales where (b.Name.ToLower() == cursub.Name.ToLower() || b.Slug.ToLower() == cursub.Slug.ToLower()) && b.AreaId == curarea.Id && // New york, queens | washington, queens are accepted b.Id != cursub.LocaleId && b.Hidden == false select b).FirstOrDefault(); if (temp != null) { return(false); //name already used } else { //db.Entry(loc).State = EntityState.Modified; var toedit = db.Locales.Find(cursub.LocaleId); toedit.Name = cursub.Name; toedit.Slug = cursub.Slug; toedit.AreaId = curarea.Id; db.SaveChanges(); return(true); } }
public ActionResult LocaleEdit(ModifyLocaleViewModel cursub) { if (ModelState.IsValid) { if (locl.AdminLocaleModify(cursub)) { var curarea = (from f in db.Areas where f.Name == cursub.SelectArea select f).FirstOrDefault(); return(RedirectToAction("AreaDetail", new { areaID = curarea.Id })); } } TempData["error"] = "Invalid Modification.The name or slug already exists."; return(View(cursub)); }
public ActionResult LocaleEdit(int?localeID) { if (localeID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //authorize admin if (acl.AuthorizeAdmin(User.Identity.GetUserId()) == false) { return(HttpNotFound()); } //check legal if (acl.CheckLocaleLegal((int)localeID) == false) { return(HttpNotFound()); } var areas = (from f in db.Areas where f.Hidden == false select f).ToList(); ViewData["areas"] = areas; var curlocale = db.Locales.Find(localeID); var curarea = db.Areas.Find(curlocale.AreaId); ModifyLocaleViewModel temp = new ModifyLocaleViewModel { Name = curlocale.Name, SelectArea = curarea.Name, Slug = curlocale.Slug, LocaleId = curlocale.Id }; return(View(temp)); }