Exemple #1
0
        public async Task <IActionResult> Upsert(MedicationViewModel obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Medication.Id == 0)
                {
                    await _meRepo.CreateAsync(SD.MedicationAPIPath, obj.Medication, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _meRepo.UpdateAsync(SD.MedicationAPIPath + obj.Medication.Id, obj.Medication, HttpContext.Session.GetString("JWToken"));
                }
                if (TempData["residentId"] != null)
                {
                    return(RedirectToAction("Index", "Medications", new { residentId = TempData["residentId"] }));
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            IEnumerable <Resident> residentList = await _reRepo.GetAllAsync(SD.ResidentAPIPath, HttpContext.Session.GetString("JWToken"));

            MedicationViewModel objVM = new MedicationViewModel()
            {
                ResidentList = residentList.Select(i => new SelectListItem()
                {
                    Text  = i.FirstName + " " + i.LastName,
                    Value = i.Id.ToString()
                }),
                Medication = new Medication()
            };

            return(View(objVM));
        }
Exemple #2
0
        public async Task CreateAsync(Dto.Medication medication)
        {
            if (medication.Quantity < 1)
            {
                throw new ArgumentException("Quantity must be greater than 0");
            }

            var repoMedication = await medicationRepository.GetByNameOrIdAsync(medication.Name, medication.Id).ConfigureAwait(false);

            if (repoMedication != null)
            {
                throw new ArgumentException("Medication already exists");
            }

            await medicationRepository.CreateAsync(medication.ToModel()).ConfigureAwait(false);
        }