Example #1
0
        public IActionResult Edit([Bind("DataErrorId,StatusId,Details,UseCase,EmployeeName,AssignedToUserId")] DataErrorViewModel vmDataError)
        {
            if (HttpContext == null ||
                HttpContext.Session == null ||
                HttpContext.Session.GetObject <UserViewModel>(MiscConstants.USER_SESSION_VM_KEY) == null)
            {
                return(RedirectToAction("Warning", "Home"));
            }

            string logSnippet = new StringBuilder("[")
                                .Append(DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"))
                                .Append("][DataErrorsController][Edit][HttpPost] => ")
                                .ToString();
            UserViewModel qmsUserVM = HttpContext.Session.GetObject <UserViewModel>(MiscConstants.USER_SESSION_VM_KEY);
            User          qmsUser   = _userService.RetrieveByEmailAddress(qmsUserVM.EmailAddress);

            Console.WriteLine(logSnippet + $"(qmsUserVM): {qmsUserVM}");

            Console.WriteLine(logSnippet + $"(vmDataError.DataErrorId).....: '{vmDataError.DataErrorId}'");
            Console.WriteLine(logSnippet + $"(vmDataError.StatusId)........: '{vmDataError.StatusId}'");
            Console.WriteLine(logSnippet + $"(vmDataError.Details).........: '{vmDataError.Details}'");
            Console.WriteLine(logSnippet + $"(vmDataError.UseCase).........: '{vmDataError.UseCase}'");
            Console.WriteLine(logSnippet + $"(vmDataError.EmployeeName)....: '{vmDataError.EmployeeName}'");
            Console.WriteLine(logSnippet + $"(vmDataError.AssignedToUserId): '{vmDataError.AssignedToUserId}'");
            Console.WriteLine(logSnippet + $"(ModelState.IsValid)..........: '{ModelState.IsValid}'");


            if (ModelState.IsValid)
            {
                int?correctiveActionId = _dataErrorService.Save(vmDataError.DataErrorId, vmDataError.Details, Int32.Parse(vmDataError.StatusId), qmsUser, vmDataError.AssignedToUserId);
                Console.WriteLine(logSnippet + $"(correctiveActionId.HasValue): '{correctiveActionId.HasValue}'");
                Console.WriteLine(logSnippet + $"(correctiveActionId).........: '{correctiveActionId}'");

                if (correctiveActionId.HasValue)
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // PREPARE SUCCESS MESSAGE FOR USER
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    string msgKey = Guid.NewGuid().ToString();
                    string msgVal = $"You have successfully converted Data Error #{vmDataError.DataErrorId} for {vmDataError.EmployeeName} into the below Corrective Action #{correctiveActionId.Value}.";
                    HttpContext.Session.SetObject(msgKey, msgVal);

                    return(RedirectToAction("Edit", "CorrectiveActions", new { @id = correctiveActionId.Value, @useCase = vmDataError.UseCase, @mk = msgKey }));
                }
                else
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // PREPARE SUCCESS MESSAGE FOR USER
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    string msgKey = Guid.NewGuid().ToString();
                    string msgVal = $"EHRI/Data Error with an ID of {vmDataError.DataErrorId} has been updated for {vmDataError.EmployeeName}";
                    HttpContext.Session.SetObject(msgKey, msgVal);

                    return(RedirectToAction("Index", "Home", new { @mk = msgKey }));
                }
            }

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // INVALID MODEL STATE PROCESSING
            //////////////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // RETRIEVE DATA ERROR UI MODEL CLASS FROM DATA ERROR SERVICE
            //////////////////////////////////////////////////////////////////////////////////////////////////
            DataError svcDataError = _dataErrorService.RetrieveById(vmDataError.DataErrorId, qmsUser);

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // ACTION DROPDOWN
            //////////////////////////////////////////////////////////////////////////////////////////////////
            Console.WriteLine(logSnippet + $"(svcDataError.StatusId.HasValue): '{svcDataError.StatusId.HasValue}'");
            Console.WriteLine(logSnippet + $"(svcDataError.StatusId): '{svcDataError.StatusId}'");
            List <Status> statusList = _referenceService.RetrieveAvailableActionsList(svcDataError.StatusId.Value, qmsUser.Organization, WorkItemTypeEnum.EHRI);

            ViewBag.StatusTypeItems = new SelectList(statusList, "StatusId", "StatusLabel");

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // NEED TO FIND THE CORRECT 'LIST' CONTROLLER (CA or DE) BASED ON THE USE CASE VALUE PASSED INTO THIS METHOD
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            List <ModuleMenuItem> moduleMenuItems = HttpContext.Session.GetObject <List <ModuleMenuItem> >(MiscConstants.MODULE_MENU_ITEMS_SESSION_KEY);

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // MAP DATA ERROR UI MODEL CLASS TO DATA ERROR VIEW MODEL CLASS
            //////////////////////////////////////////////////////////////////////////////////////////////////
            DataErrorViewModel vmDataError2 = DataErrorUtil.MapToViewModel(qmsUserVM, svcDataError, vmDataError.UseCase, moduleMenuItems);

            return(View(vmDataError2));
        }
Example #2
0
        public IActionResult Edit(int id, string useCase)
        {
            if (HttpContext == null ||
                HttpContext.Session == null ||
                HttpContext.Session.GetObject <UserViewModel>(MiscConstants.USER_SESSION_VM_KEY) == null)
            {
                return(RedirectToAction("Warning", "Home"));
            }

            string logSnippet = new StringBuilder("[")
                                .Append(DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"))
                                .Append("][DataErrorsController][HttpGet][Edit] => ")
                                .ToString();

            Console.WriteLine(logSnippet + $"(id).....: '{id}'");
            Console.WriteLine(logSnippet + $"(useCase).: '{useCase}'");

            UserViewModel qmsUserVM = HttpContext.Session.GetObject <UserViewModel>(MiscConstants.USER_SESSION_VM_KEY);
            User          qmsUser   = _userService.RetrieveByEmailAddress(qmsUserVM.EmailAddress);

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // PERMISSION CHECK
            //////////////////////////////////////////////////////////////////////////////////////////////////
            if (useCase.Equals(UseCaseConstants.VIEW_ALL_EHRI_ERRORS))
            {
                this.doPermissionCheck(qmsUser, PermissionCodeConstants.VIEW_ALL_EHRI_ERRORS);
            }
            else if (useCase.Equals(UseCaseConstants.VIEW_ALL_ARCHIVED_EHRI_ERRORS))
            {
                this.doPermissionCheck(qmsUser, PermissionCodeConstants.VIEW_ALL_ARCHIVED_EHRI_ERRORS);
            }
            else if (useCase.Equals(UseCaseConstants.VIEW_EHRI_ERRORS_FOR_USER))
            {
                this.doPermissionCheck(qmsUser, PermissionCodeConstants.VIEW_EHRI_ERRORS_FOR_USER);
            }
            else if (useCase.Equals(UseCaseConstants.VIEW_EHRI_ERRORS_FOR_ORG))
            {
                this.doPermissionCheck(qmsUser, PermissionCodeConstants.VIEW_EHRI_ERRORS_FOR_ORG);
            }
            else if (useCase.Equals(UseCaseConstants.VIEW_ARCHIVED_EHRI_ERRORS_FOR_USER))
            {
                this.doPermissionCheck(qmsUser, PermissionCodeConstants.VIEW_ARCHIVED_EHRI_ERRORS_FOR_USER);
            }
            else if (useCase.Equals(UseCaseConstants.VIEW_ARCHIVED_EHRI_ERRORS_FOR_ORG))
            {
                this.doPermissionCheck(qmsUser, PermissionCodeConstants.VIEW_ARCHIVED_EHRI_ERRORS_FOR_ORG);
            }
            else
            {
                return(RedirectToAction("UnauthorizedAccess", "Home"));
            }

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // RETRIEVE DATA ERROR UI MODEL CLASS FROM DATA ERROR SERVICE
            //////////////////////////////////////////////////////////////////////////////////////////////////
            DataError svcDataError = _dataErrorService.RetrieveById(id, qmsUser);

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // ACTION DROPDOWN
            //////////////////////////////////////////////////////////////////////////////////////////////////
            Console.WriteLine(logSnippet + $"(svcDataError.StatusId.HasValue): '{svcDataError.StatusId.HasValue}'");
            Console.WriteLine(logSnippet + $"(svcDataError.StatusId): '{svcDataError.StatusId}'");
            List <Status> statusList = _referenceService.RetrieveAvailableActionsList(svcDataError.StatusId.Value, qmsUser.Organization, WorkItemTypeEnum.EHRI);

            ViewBag.StatusTypeItems = new SelectList(statusList, "StatusId", "StatusLabel");

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // ASSIGNEE DROPDOWN
            //////////////////////////////////////////////////////////////////////////////////////////////////
            Console.WriteLine(logSnippet + $"(qmsUserVM.CanAssignTasks).: '{qmsUserVM.CanAssignTasks}'");
            Console.WriteLine(logSnippet + $"(svcDataError.IsAssignable): '{svcDataError.IsAssignable}'");

            if (qmsUserVM.CanAssignTasks && svcDataError.IsAssignable)
            {
                List <User> usersByOrgList = _userService.RetrieveUsersByOrganizationId(qmsUser.OrgId.Value);
                if (svcDataError.AssignedByUserId.HasValue)
                {
                    ViewBag.AssignedToUserItems = new SelectList(usersByOrgList, "UserId", "DisplayName", svcDataError.AssignedByUserId.Value);
                }
                else
                {
                    ViewBag.AssignedToUserItems = new SelectList(usersByOrgList, "UserId", "DisplayName");
                }
            }

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // NEED TO FIND THE CORRECT 'LIST' CONTROLLER (CA or DE) BASED ON THE USE CASE VALUE PASSED INTO THIS METHOD
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            List <ModuleMenuItem> moduleMenuItems = HttpContext.Session.GetObject <List <ModuleMenuItem> >(MiscConstants.MODULE_MENU_ITEMS_SESSION_KEY);

            //////////////////////////////////////////////////////////////////////////////////////////////////
            // MAP DATA ERROR UI MODEL CLASS TO DATA ERROR VIEW MODEL CLASS
            //////////////////////////////////////////////////////////////////////////////////////////////////
            DataErrorViewModel vmDataError = DataErrorUtil.MapToViewModel(qmsUserVM, svcDataError, useCase, moduleMenuItems);

            return(View(vmDataError));
        }