Example #1
0
        public IActionResult Delete(int id)
        {
            var model = new MedicineUpdateModel();

            model.Delete(id);
            return(RedirectToAction("Index"));
        }
Example #2
0
        public IActionResult Edit(int id)
        {
            var model            = new MedicineUpdateModel();
            var MedicineCatModel = new MedicineCategoryViewModel();

            model.medCatModel = MedicineCatModel.GetSelectedMedicineCategories(id);
            model.Load(id);
            return(View(model));
        }
Example #3
0
 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));
 }
Example #4
0
        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));
        }
Example #5
0
        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));
        }
Example #6
0
        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);
        }