public async Task RequestNewScript(RequestScriptModel model) { try { var patient = await _userService.GetCurrentUserAsync <Patient>(UserTypes.Patient) as Patient; if (patient == null) { throw new Exception("user is not a patient"); } Script script = new Script() { Status = ScriptStatuses.Pending, PatientId = patient.Id, Request = model.Request, DoctorId = model.Doctor }; await _context.Scripts.AddAsync(script); await _context.SaveChangesAsync(); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult> RequestScript(RequestScriptModel model) { try { if (!ModelState.IsValid) { throw new Exception(ModelState.ErrorGathering()); } await _scriptService.RequestNewScript(model); } catch (Exception ex) { TempData["message"] = ex.Message; } return(RedirectToAction("Index", "Home")); }