public ActionResult Create(FormCollection collection)//[Bind(Include = "ID,Ndc,Name,Producer,MImage,GenericName,ActiveIngredients,Properties")] MedicineViewModel medicineViewModel) { try { DetailsViewModel DescriptionList = new DetailsViewModel(); ImageValidateLogic bl = new ImageValidateLogic(); string filePath = Server.MapPath(Url.Content($"~/images/{collection["MImage"].ToString()}")); DescriptionList.Descriptions = new List <string>(bl.CheckImage(filePath)); DrugAdminLogic bl2 = new DrugAdminLogic(); bl2.AddDrug(collection["Name"], collection["GenericName"], collection["Producer"], collection["ActiveIngredients"], collection["Properties"], collection["MImage"].ToString(), collection["Ndc"]); ViewBag.Message = String.Format("The medicine was added successfully."); return(View("Home"));// RedirectToAction("Home"); } catch (Exception ex) { if (ex.Message == "The medicine already exists in the system") { ViewBag.Message = String.Format("The medicine already exists in the system , try again"); } if (ex.Message == "not a drug image") { ViewBag.Message = String.Format("The image that you selected is not a medicine , try again"); } return(View()); } }
public ActionResult Edit(FormCollection collection)//[Bind(Include = "ID,Ndc,Name,Producer,MImage,GenericName,ActiveIngredients,Properties")] MedicineViewModel medicineViewModel) { try { DrugAdminLogic bl2 = new DrugAdminLogic(); if (collection["MImage"] == string.Empty) { bl2.EditDrug(collection["Name"], collection["GenericName"], collection["Producer"], collection["ActiveIngredients"], collection["Properties"], null, collection["Ndc"]); } else { DetailsViewModel DescriptionList = new DetailsViewModel(); ImageValidateLogic bl = new ImageValidateLogic(); string filePath = "C:\\Users\\מירי\\Downloads\\Gui_\\Gui_\\images\\" + collection["MImage"];// Server.MapPath(Url.Content($"{ collection["MImage"].ToString()}")); DescriptionList.Descriptions = new List <string>(bl.CheckImage(filePath)); bl2.EditDrug(collection["Name"], collection["GenericName"], collection["Producer"], collection["ActiveIngredients"], collection["Properties"], collection["MImage"], collection["Ndc"]); } ViewBag.Message = String.Format("The medicine was edited successfully."); return(View("Home")); } catch (Exception ex) { if (ex.Message == "not a drug image") { ViewBag.Message = String.Format("The image that you selected is not a medicine , try again"); } return(View()); } }