public async Task <ActionResult> DeleteConfirmed(int id) { TypeCustomViewModel typeCustomViewModel = await db.CustomTypes.FindAsync(id); db.CustomTypes.Remove(typeCustomViewModel); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,ImagePath")] TypeCustomViewModel typeCustomViewModel) { if (ModelState.IsValid) { db.Entry(typeCustomViewModel).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(typeCustomViewModel)); }
// GET: TypeCustom/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TypeCustomViewModel typeCustomViewModel = await db.CustomTypes.FindAsync(id); if (typeCustomViewModel == null) { return(HttpNotFound()); } return(View(typeCustomViewModel)); }
Create([Bind(Include = "Id,Name,ImagePath,ImageFile")] TypeCustomViewModel typeTaskViewModel) { if (ModelState.IsValid) { string fileName = Path.GetFileName(typeTaskViewModel.ImageFile.FileName); string path = Server.MapPath("~/Files/" + fileName); // сохраняем файл в папку Files в проекте typeTaskViewModel.ImageFile.SaveAs(path); typeTaskViewModel.ImagePath = "~/Files/" + fileName; db.CustomTypes.Add(typeTaskViewModel); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(typeTaskViewModel)); }