Ejemplo n.º 1
0
        private string ProcessUploadedFile(AddMedicationViewModel model)
        {
            string uniqueFileName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Photo.CopyTo(fileStream);
                }
            }

            return(uniqueFileName);
        }
Ejemplo n.º 2
0
        public IActionResult Add(AddMedicationViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedFile(model);

                //MedicationCategory newMedicationCategory = context.Categories.Single(c => c.ID == model.Category);
                Medication newMedication = new Medication
                {
                    Name         = model.Name,
                    Description  = model.Description,
                    PhotoPath    = uniqueFileName,
                    CategoryName = model.CategoryName,
                    AccountId    = model.AccountId,

                    Dosage         = model.Dosage,
                    MondayMorn     = model.MondayMorn,
                    MondayAfter    = model.MondayAfter,
                    MondayEve      = model.MondayEve,
                    TuesdayMorn    = model.TuesdayMorn,
                    TuesdayAfter   = model.TuesdayAfter,
                    TuesdayEve     = model.TuesdayEve,
                    WednesdayMorn  = model.WednesdayMorn,
                    WednesdayAfter = model.WednesdayAfter,
                    WednesdayEve   = model.WednesdayEve,
                    ThursdayMorn   = model.ThursdayMorn,
                    ThursdayAfter  = model.ThursdayAfter,
                    ThursdayEve    = model.ThursdayEve,
                    FridayMorn     = model.FridayMorn,
                    FridayAfter    = model.FridayAfter,
                    FridayEve      = model.FridayEve,
                    SaturdayMorn   = model.SaturdayMorn,
                    SaturdayAfter  = model.SaturdayAfter,
                    SaturdayEve    = model.SaturdayEve,
                    SundayMorn     = model.SundayMorn,
                    SundayAfter    = model.SundayAfter,
                    SundayEve      = model.SundayEve
                };
                context.Medications.Add(newMedication);
                context.SaveChanges();

                return(RedirectToAction("Index", "Medication"));
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public IActionResult Add()
        {
            AddMedicationViewModel addMedicationViewModel = new AddMedicationViewModel(context.Categories.ToList());

            return(View(addMedicationViewModel));
        }