Exemplo n.º 1
0
        public ActionResult Complain()
        {
            var model = new CreateComplaintViewModel();

            PopulateCreateComplaintModel(model);
            return(PartialView("_Complain", model));
        }
Exemplo n.º 2
0
 public Complaint(CreateComplaintViewModel m)
 {
     // Received
     DateReceived = m.DateReceivedDate.Value.Date;
     if (m.DateReceivedTime.HasValue)
     {
         DateReceived = DateReceived.Add(m.DateReceivedTime.Value.TimeOfDay);
     }
     ReceivedById = m.ReceivedById;
     // Caller
     CallerName                 = m.CallerName;
     CallerRepresents           = m.CallerRepresents;
     CallerStreet               = m.CallerStreet;
     CallerStreet2              = m.CallerStreet2;
     CallerCity                 = m.CallerCity;
     CallerStateId              = m.CallerStateId;
     CallerPostalCode           = m.CallerPostalCode;
     CallerPhoneNumber          = m.CallerPhoneNumber;
     CallerPhoneType            = m.CallerPhoneType;
     CallerSecondaryPhoneNumber = m.CallerSecondaryPhoneNumber;
     CallerSecondaryPhoneType   = m.CallerSecondaryPhoneType;
     CallerTertiaryPhoneNumber  = m.CallerTertiaryPhoneNumber;
     CallerTertiaryPhoneType    = m.CallerTertiaryPhoneType;
     CallerEmail                = m.CallerEmail;
     // Complaint
     ComplaintNature     = m.ComplaintNature;
     ComplaintLocation   = m.ComplaintLocation;
     ComplaintDirections = m.ComplaintDirections;
     ComplaintCity       = m.ComplaintCity;
     ComplaintCountyId   = m.ComplaintCountyId;
     PrimaryConcernId    = m.PrimaryConcernId;
     SecondaryConcernId  = m.SecondaryConcernId;
     // Source
     SourceFacilityId           = m.SourceFacilityId;
     SourceContactName          = m.SourceContactName;
     SourceFacilityName         = m.SourceFacilityName;
     SourceStreet               = m.SourceStreet;
     SourceStreet2              = m.SourceStreet2;
     SourceCity                 = m.SourceCity;
     SourceStateId              = m.SourceStateId;
     SourcePostalCode           = m.SourcePostalCode;
     SourcePhoneNumber          = m.SourcePhoneNumber;
     SourcePhoneType            = m.SourcePhoneType;
     SourceSecondaryPhoneNumber = m.SourceSecondaryPhoneNumber;
     SourceSecondaryPhoneType   = m.SourceSecondaryPhoneType;
     SourceTertiaryPhoneNumber  = m.SourceTertiaryPhoneNumber;
     SourceTertiaryPhoneType    = m.SourceTertiaryPhoneType;
     SourceEmail                = m.SourceEmail;
     // Assignment
     CurrentOfficeId = m.CurrentOfficeId.Value;
     CurrentOwnerId  = m.CurrentOwnerId;
 }
Exemplo n.º 3
0
        public CreateComplaintViewModel getCreateComplaintViewModel()
        {
            CreateComplaintViewModel _viewModel = new CreateComplaintViewModel
            {
                _hospitals           = hr.GetHospitals(),
                _communications      = this.GetCommunicationForm(),
                _complaint_type      = ctr.GetComplaintTypes(),
                _complaintAssistance = cat.GetComplaintAssistance(),
                _facility_type       = db.facilityType.Select(s => s.Name).ToList()
            };

            return(_viewModel);
        }
Exemplo n.º 4
0
        private void PopulateCreateComplaintModel(CreateComplaintViewModel model)
        {
            var severities      = _complaintSeverityService.GetAll();
            var defaultSeverity = severities.Where(s => s.IsDefault).FirstOrDefault();
            var tags            = _tagService.GetAll();

            model.Severities = severities.Select(s => new SelectListItem()
            {
                Text     = s.Name,
                Selected = s.IsDefault,
                Value    = s.Id.ToString()
            });

            model.SelectedComplaintSeverityId = defaultSeverity == null ? (Guid?)null : defaultSeverity.Id;
            model.ExistingTags = tags.Select(t => _tagBuilder.BuildViewModel(t)).ToList();
        }
Exemplo n.º 5
0
        // GET: Complaints/Create
        public async Task <IActionResult> Create()
        {
            var currentUser = await GetCurrentUserAsync();

            if (currentUser == null)
            {
                throw new Exception("Current user not found");
            }

            var model = new CreateComplaintViewModel()
            {
                SelectLists               = await _dal.GetCommonSelectListsAsync(currentUser.OfficeId),
                ReceivedById              = currentUser.Id,
                DateReceivedDate          = DateTime.Now,
                CurrentOfficeId           = currentUser?.OfficeId,
                DisableCurrentOwnerSelect = false,
            };

            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult CreateComplaint()
        {
            CreateComplaintViewModel createComplaintVM = this.cr.getCreateComplaintViewModel();

            return(View(createComplaintVM));
        }
Exemplo n.º 7
0
        public ActionResult Filter()
        {
            CreateComplaintViewModel filterViewData = this.cr.getCreateComplaintViewModel();

            return(PartialView(filterViewData));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create(CreateComplaintViewModel model)
        {
            var currentUser = await GetCurrentUserAsync();

            if (currentUser == null)
            {
                throw new Exception("Current user not found");
            }

            string msg = null;

            if (!ModelState.IsValid)
            {
                msg = $"The Complaint was not created. Please fix the errors shown below.";
                ViewData["AlertMessage"] = new AlertViewModel(msg, AlertStatus.Error, "Error");

                // Populate the select lists before returning the model
                model.SelectLists = await _dal.GetCommonSelectListsAsync(model.CurrentOfficeId);

                model.DisableCurrentOwnerSelect = !(model.CurrentOfficeId == currentUser.OfficeId ||
                                                    User.IsInRole(CtsRole.DivisionManager.ToString()));

                return(View(model));
            }

            if ((!User.IsInRole(CtsRole.DivisionManager.ToString()) &&
                 model.CurrentOfficeId != currentUser.OfficeId) ||
                model.CurrentOwnerId == CTS.SelectUserMasterText)
            {
                model.CurrentOwnerId = null;
            }

            var complaint = new Complaint(model)
            {
                Status      = ComplaintStatus.New,
                DateEntered = DateTime.Now,
                EnteredBy   = currentUser,
                DateCurrentOwnerAssigned = (model.CurrentOwnerId != null) ? (DateTime?)DateTime.Now : null,
                DateCurrentOwnerAccepted = (model.CurrentOwnerId != null && model.CurrentOwnerId == currentUser.Id) ? (DateTime?)DateTime.Now : null,
            };

            // Save main complaint details
            try
            {
                _context.Add(complaint);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                ex.Data.Add("Action", "Saving Complaint");
                ex.Data.Add("ViewModel", model);
                await _errorLogger.LogErrorAsync(ex, (User == null)? "Unknown" : User.Identity.Name, MethodBase.GetCurrentMethod().Name);

                msg = "There was an error saving the complaint. Please try again or contact support.";
                ViewData["AlertMessage"] = new AlertViewModel(msg, AlertStatus.Error, "Error");

                // Populate the select lists before returning the model
                model.SelectLists = await _dal.GetCommonSelectListsAsync(model.CurrentOfficeId);

                model.DisableCurrentOwnerSelect = !(model.CurrentOfficeId == currentUser.OfficeId ||
                                                    User.IsInRole(CtsRole.DivisionManager.ToString()));
                return(View(model));
            }

            // The complaint was successfully saved. Now start tracking any subsequent errors.
            var saveStatus = AlertStatus.Success;

            // Save initial complaint transitions
            bool transitionSaveError = false;
            Guid transitionId        = Guid.Empty;

            try
            {
                transitionId = await AddComplaintTransition(new ComplaintTransition()
                {
                    ComplaintId           = complaint.Id,
                    TransferredByUserId   = currentUser.Id,
                    TransferredToOfficeId = model.CurrentOfficeId,
                    TransitionType        = TransitionType.New,
                });

                if (model.CurrentOwnerId != null)
                {
                    complaint.CurrentAssignmentTransitionId = await AddComplaintTransition(new ComplaintTransition()
                    {
                        ComplaintId           = complaint.Id,
                        TransferredByUserId   = currentUser.Id,
                        TransferredToUserId   = model.CurrentOwnerId,
                        TransferredToOfficeId = model.CurrentOfficeId,
                        DateAccepted          = (currentUser.Id == model.CurrentOwnerId) ? (DateTime?)DateTime.Now : null,
                        TransitionType        = TransitionType.Assigned,
                    });

                    if (model.CurrentOwnerId == currentUser.Id)
                    {
                        complaint.Status = ComplaintStatus.UnderInvestigation;
                    }

                    _context.Update(complaint);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("Action", "Saving Transitions");
                ex.Data.Add("Complaint ID", complaint.Id);
                ex.Data.Add("ViewModel", model);
                ex.Data.Add("Complaint Model", complaint);
                ex.Data.Add("Transition ID", transitionId);
                await _errorLogger.LogErrorAsync(ex, (User == null)? "Unknown" : User.Identity.Name, MethodBase.GetCurrentMethod().Name);

                saveStatus          = AlertStatus.Warning;
                transitionSaveError = true;
            }

            // Email appropriate recipients
            bool emailError = false;

            try
            {
                var complaintUrl = Url.Action("Details", "Complaints", new { id = complaint.Id }, protocol: HttpContext.Request.Scheme);
                if (complaint.CurrentOwnerId == null)
                {
                    // Email Master of current Office
                    var currentOffice = await _context.LookupOffices.FindAsync(complaint.CurrentOfficeId);

                    var officeMaster = await _userManager.FindByIdAsync(currentOffice.MasterUserId);

                    var masterEmail = await _userManager.GetEmailAsync(officeMaster);

                    await _emailSender.SendEmailAsync(
                        masterEmail,
                        string.Format(EmailTemplates.ComplaintOpenedToMaster.Subject, complaint.Id),
                        string.Format(EmailTemplates.ComplaintOpenedToMaster.PlainBody, complaint.Id, complaintUrl, currentOffice.Name),
                        string.Format(EmailTemplates.ComplaintOpenedToMaster.HtmlBody, complaint.Id, complaintUrl, currentOffice.Name),
                        !officeMaster.Active || !officeMaster.EmailConfirmed,
                        replyTo : currentUser.Email);
                }
                else
                {
                    // Email new owner
                    var currentOwner = await _userManager.FindByIdAsync(complaint.CurrentOwnerId);

                    var currentOwnerEmail = await _userManager.GetEmailAsync(currentOwner);

                    bool isValidUser = currentOwner.Active && currentOwner.EmailConfirmed;
                    await _emailSender.SendEmailAsync(
                        currentOwnerEmail,
                        string.Format(EmailTemplates.ComplaintAssigned.Subject, complaint.Id),
                        string.Format(EmailTemplates.ComplaintAssigned.PlainBody, complaint.Id, complaintUrl),
                        string.Format(EmailTemplates.ComplaintAssigned.HtmlBody, complaint.Id, complaintUrl),
                        !isValidUser,
                        replyTo : currentUser.Email);
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("Action", "Emailing recipients");
                ex.Data.Add("Complaint ID", complaint.Id);
                ex.Data.Add("ViewModel", model);
                ex.Data.Add("Complaint Model", complaint);
                await _errorLogger.LogErrorAsync(ex, (User == null)? "Unknown" : User.Identity.Name, MethodBase.GetCurrentMethod().Name);

                saveStatus = AlertStatus.Warning;
                emailError = true;
            }

            // Save attachments
            bool   attachmentsError       = false;
            int    fileCount              = 0;
            string attachmentErrorMessage = null;

            if (model.Attachments != null && model.Attachments.Count > 0)
            {
                switch (_fileService.ValidateUploadedFiles(model.Attachments))
                {
                case FilesValidationResult.TooMany:
                    saveStatus             = AlertStatus.Warning;
                    attachmentsError       = true;
                    attachmentErrorMessage = "No more than 10 files can be uploaded at a time. ";
                    break;

                case FilesValidationResult.WrongType:
                    saveStatus             = AlertStatus.Warning;
                    attachmentsError       = true;
                    attachmentErrorMessage = "An invalid file type was selected. (Supported file types are images, documents, and spreadsheets.) ";
                    break;

                case FilesValidationResult.Valid:
                    var savedFileList = new List <Attachment>();

                    try
                    {
                        foreach (var file in model.Attachments)
                        {
                            var attachment = await _fileService.SaveAttachmentAsync(file);

                            if (attachment != null)
                            {
                                attachment.ComplaintId  = complaint.Id;
                                attachment.UploadedById = currentUser.Id;
                                _context.Add(attachment);
                                savedFileList.Add(attachment);
                                fileCount++;
                            }
                        }

                        await _context.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        ex.Data.Add("Action", "Saving Attachments");
                        ex.Data.Add("Complaint ID", complaint.Id);
                        ex.Data.Add("ViewModel", model);
                        ex.Data.Add("Complaint Model", complaint);
                        await _errorLogger.LogErrorAsync(ex, (User == null)? "Unknown" : User.Identity.Name, MethodBase.GetCurrentMethod().Name);

                        foreach (var attachment in savedFileList)
                        {
                            await _fileService.TryDeleteFileAsync(attachment.FilePath);

                            if (attachment.IsImage)
                            {
                                await _fileService.TryDeleteFileAsync(attachment.ThumbnailPath);
                            }
                        }

                        fileCount              = 0;
                        saveStatus             = AlertStatus.Warning;
                        attachmentsError       = true;
                        attachmentErrorMessage = "An unknown database error occurred. ";
                    }
                    break;
                }
            }

            // Compile response message
            if (fileCount == 0)
            {
                msg = "The Complaint has been created. ";
            }
            else if (fileCount == 1)
            {
                msg = "The Complaint has been created and one file was attached. ";
            }
            else if (fileCount > 1)
            {
                msg = $"The Complaint has been created and {fileCount} files were attached. ";
            }

            if (saveStatus != AlertStatus.Success)
            {
                if (transitionSaveError)
                {
                    msg += "There were errors saving some of the complaint details. Please contact support. ";
                }

                if (emailError)
                {
                    msg += "There was an error emailing the recipients. Please contact support. ";
                }

                if (attachmentsError)
                {
                    msg += "There was a problem saving the attachments: " + attachmentErrorMessage + "No files were saved. ";
                }

                TempData.SaveAlertForSession(msg, AlertStatus.Warning, "Warning");
            }

            TempData.SaveAlertForSession(msg, saveStatus, saveStatus.GetDisplayName());
            return(RedirectToAction("Details", new { id = complaint.Id }));
        }
Exemplo n.º 9
0
        public ActionResult Complain(CreateComplaintViewModel model)
        {
            if (ModelState.IsValid)
            {
                var me = FacebookService.GetMe();

                var complaint = new Complaint()
                {
                    ComplaintText    = model.ComplaintText,
                    FacebookUserId   = me.FacebookUserId,
                    FacebookUserName = me.Name,
                };

                if (model.SelectedComplaintSeverityId.HasValue)
                {
                    var severity = _complaintSeverityService.Get(model.SelectedComplaintSeverityId.Value);
                    complaint.Severity = severity;
                }

                if (model.TagList.Any())
                {
                    foreach (var tagName in model.TagList)
                    {
                        var tag = _tagService.FindByName(tagName);

                        if (tag == null)
                        {
                            tag = new Tag()
                            {
                                Name = tagName
                            };
                        }

                        complaint.Tags.Add(tag);
                    }
                }

                var errors = _complaintService.Create(complaint);

                if (!errors.Any())
                {
                    if (model.PublishToWall)
                    {
                        FacebookService.Post("feed", new
                        {
                            message     = model.ComplaintText,
                            picture     = String.Format("{0}/Content/Images/angry smiley.png", Constants.RootUrl),
                            link        = String.Format("{0}/Complaint/View/{1}", Constants.RootUrl, complaint.Id),
                            caption     = "I just complained",
                            description = "I just posted a complaint on Complainatron",
                            source      = String.Format("{0}/Complaint/View/{1}", Constants.RootUrl, complaint.Id),
                        });
                    }

                    var viewModel = _complaintBuilder.BuildViewModel(complaint);
                    return(PartialView("_Complaint", viewModel));
                }
                else
                {
                    SetModelStateErrors(errors);
                }
            }

            PopulateCreateComplaintModel(model);
            return(PartialView("_Complain", model));
        }