public async Task <ActionResult> Edit(Announ ann) { db.Entry(ann).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("GetUserAnns")); }
public async Task <ActionResult> Edit(string id) { Announ ann = await db.Announs.FindAsync(Int32.Parse(id)); if (ann != null) { return(View(ann)); } else { return(View("Error", new string[] { "Объявление не найдено" })); } }
public async Task <ActionResult> Create(Announ ann) { if (ModelState.IsValid) { User cur_user = await Manager.FindByNameAsync(HttpContext.User.Identity.Name); cur_user.Announs.Add(ann); await Manager.UpdateAsync(cur_user); return(RedirectToAction("GetUserAnns")); } else { ModelState.AddModelError("", "Некорректные данные"); } return(View(ann)); }
public async Task <ActionResult> Delete([Required] string id) { if (ModelState.IsValid) { Announ ann = await db.Announs.Where(a => a.Id.ToString() == id).FirstOrDefaultAsync(); if (ann != null) { db.Announs.Remove(ann); await db.SaveChangesAsync(); return(RedirectToAction("GetUserAnns")); } else { return(View("Error", new string[] { "Не удалось найти объявление" })); } } else { return(View("Error", new string[] { "Произошла ошибка" })); } }