public IActionResult Delete(int id) { var model = new MedicineUpdateModel(); model.Delete(id); return(RedirectToAction("Index")); }
public IActionResult Edit(int id) { var model = new MedicineUpdateModel(); var MedicineCatModel = new MedicineCategoryViewModel(); model.medCatModel = MedicineCatModel.GetSelectedMedicineCategories(id); model.Load(id); return(View(model)); }
public IActionResult Edit(MedicineUpdateModel model) { if (ModelState.IsValid) { var medCatModel = new MedicineCategoryViewModel(); medCatModel.SetSelectedCategory(model.medCatModel, model.Id); string fileName = UploadedFile(model); model.Url = fileName; model.EditMedicine(); } return(View(model)); }
public IActionResult Add() { var model = new MedicineUpdateModel(); var Categories = model.GetAllCategory(); model.Categories = (from r in Categories select new SelectListItem { Value = r.Id.ToString(), Text = r.Name }).ToList(); //model.ReturnUrl = returnUrl; return(View(model)); }
public IActionResult Add([FromBody] MedicineUpdateModel model) { model.ReturnUrl = model.ReturnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { string fileName = UploadedFile(model); model.Url = fileName; model.AddNewMedicine(); } var Categories = model.GetAllCategory(); model.Categories = (from r in Categories select new SelectListItem { Value = r.Id.ToString(), Text = r.Name }).ToList(); return(View(model)); }
private string UploadedFile(MedicineUpdateModel model) { string uniqueFileName = null; if (model.Image != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "admin\\img\\"); if (model.Image.Name != null) { uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.Name + ".jpg"; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.Image.CopyTo(fileStream); } } else { return(null); } } return(uniqueFileName); }