public DashboardEditModel(
     ITracerService tracerService,
     IUserService userService,
     IContactService contactService,
     ICaseService caseService)
     : base(tracerService, userService)
 {
     _contactService = contactService;
     _caseService    = caseService;
     AddContactForm  = new AddContactForm();
 }
        public IActionResult OnPost()
        {
            var currentCase = _caseService.GetCase(AddContactForm.CaseId);

            if (currentCase != null)
            {
                CurrentAssignedCase = new CaseDetail
                {
                    Name   = currentCase.GetFullName(),
                    CaseID = currentCase.CaseID
                };
            }
            if (ModelState.IsValid)
            {
                var extraValid = true;
                if (AddContactForm.Email == null && AddContactForm.Phone == null)
                {
                    ModelState.AddModelError("AddContactForm.Email", "You must supply either an email address or phone number");
                    ModelState.AddModelError("AddContactForm.Phone", "You must supply either an email address or phone number");
                    extraValid = false;
                }
                if (extraValid)
                {
                    if (AddContactForm.ContactId.HasValue)
                    {
                        var editContact = _contactService.GetContact(AddContactForm.ContactId.Value);
                        if (editContact == null || editContact.CaseID != currentCase.CaseID)
                        {
                            return(new RedirectToPageResult("Dashboard", new { caseId = AddContactForm.CaseId }));
                        }
                        _contactService.Update(AddContactForm.getContact(editContact));
                        return(new RedirectToPageResult("Dashboard", new { caseId = AddContactForm.CaseId }));
                    }
                    else
                    {
                        _contactService.Add(AddContactForm.getContact());
                        return(new RedirectToPageResult("Dashboard", new { caseId = AddContactForm.CaseId }));
                    }
                }
            }
            return(Page());
        }