public async Task <ActionResult> Edit(MedicineCategoryModel model) { try { if (!ModelState.IsValid) { TempData["message"] = ModelState.ErrorGathering(); } var medCat = await _context.MedicineCategories.FirstOrDefaultAsync(x => x.Id.Equals(model.Id)); if (medCat != null) { medCat.Name = model.Name; _context.MedicineCategories.Update(medCat); await _context.SaveChangesAsync(); } else { TempData["message"] = "Medicine Category not found."; } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { TempData["message"] = ex.Message; return(View()); } }
public async Task <ActionResult> Edit(int Id) { MedicineCategoryModel model = new MedicineCategoryModel(); var medCat = await _context.MedicineCategories.FirstOrDefaultAsync(x => x.Id.Equals(Id)); model.Name = medCat.Name; return(View(model)); }
public async Task <ActionResult> Add(MedicineCategoryModel model) { try { if (ModelState.IsValid) { MedicineCategory medCat = new MedicineCategory(); medCat.Name = model.Name; await _context.MedicineCategories.AddAsync(medCat); await _context.SaveChangesAsync(); } else { TempData["message"] = ModelState.ErrorGathering(); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { TempData["message"] = ex.Message; return(RedirectToAction(nameof(Index))); } }
public ActionResult Add() { MedicineCategoryModel model = new MedicineCategoryModel(); return(View(model)); }