public ActionResult Create(MedicineViewModel mvm, HttpPostedFileBase ImageFile)//[Bind(Include = "Id,Name,Producer,GenericName,ActiveIngredients,PortionProperties")] MedicineViewModel mvm) { if (ModelState.IsValid) { IBL bl = new BLImplement(); Medicine medicine = new Medicine() { //Name = collection["Name"], //GenericName = collection["GenericName"], //ActiveIngredients = collection["ActiveIngredients"], //PortionProperties = collection["PortionProperties"], //Producer = collection["Producer"] Name = mvm.Name, GenericName = mvm.GenericName, ActiveIngredients = mvm.ActiveIngredients, PortionProperties = mvm.PortionProperties, Producer = mvm.Producer }; try { bl.addMedicine(medicine, ImageFile); ViewBag.Message = String.Format("The medicine {0} is successfully added", medicine.Name); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Message = String.Format(ex.Message); return(RedirectToAction("Index")); } } return(View(new MedicineViewModel())); }
public ActionResult Create(MedicineViewModel mvm, HttpPostedFileBase ImageFile) { if (ModelState.IsValid) { IBL bl = new BLImplement(); Medicine medicine = new Medicine() { Name = mvm.Name, GenericName = mvm.GenericName, ActiveIngredients = mvm.ActiveIngredients, PortionProperties = mvm.PortionProperties, Producer = mvm.Producer }; try { if (ImageFile != null) { bl.addMedicine(medicine); } else { bl.addMedicine(medicine, ImageFile); } bl.addMedicine(medicine, ImageFile); ViewBag.Message = String.Format("The medicine {0} is successfully added", medicine.Name); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Message = String.Format(ex.Message); return(RedirectToAction("Index")); } } return(View(new MedicineViewModel())); }