Esempio n. 1
0
 public async Task <ActionResult> ResponseToScript(RespondToScriptModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             throw new Exception(ModelState.ErrorGathering());
         }
         await _scriptService.RespondToScript(model);
     }
     catch (Exception ex)
     {
         TempData["message"] = ex.Message;
     }
     return(RedirectToAction("Index", "Home"));
 }
Esempio n. 2
0
        public async Task RespondToScript(RespondToScriptModel model)
        {
            try
            {
                var doc = await _userService.GetCurrentUserAsync <Doctor>(UserTypes.Doctor) as Doctor;

                if (doc == null)
                {
                    throw new Exception("user is not a doctor");
                }
                Script script = await _context.Scripts.FindAsync(model.Id);

                List <ScriptDetail> details = new List <ScriptDetail>();
                var medicines = model.Medicines.Split(',').ToList();
                medicines.RemoveAll(x => string.IsNullOrWhiteSpace(x));
                var medicineIds = medicines.Select(x => Convert.ToInt32(x));
                foreach (var medId in medicineIds)
                {
                    ScriptDetail detail = new ScriptDetail()
                    {
                        MedicineId = medId,
                        ScriptId   = script.Id,
                    };
                    details.Add(detail);
                }
                if (details.Any())
                {
                    script.Status   = ScriptStatuses.Responded;
                    script.DoctorId = doc.Id;
                    script.Response = model.Response;
                    await _context.ScriptDetails.AddRangeAsync(details);

                    _context.Scripts.Update(script);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public async Task <ActionResult> ResponseToScript(int id)
        {
            try
            {
                var item = await _context.Scripts.Include(x => x.Patient).FirstOrDefaultAsync(x => x.Id.Equals(id));

                if (item == null)
                {
                    throw new Exception("script not found");
                }
                var result = new RespondToScriptModel();
                result.Request     = item.Request;
                result.PatientName = $"{item.Patient.Firstname} {item.Patient.Lastname}";
                return(View(result));
            }
            catch (Exception ex)
            {
                TempData["message"] = ex.Message;
            }
            return(RedirectToAction(nameof(Index)));
        }