Ejemplo n.º 1
0
 public ApplicationResponse(T value, ApplicationResponseStatus status, string message)
 {
     this.Value   = value;
     this.Status  = status;
     this.Message = message;
 }
Ejemplo n.º 2
0
        public List <ApplicationResponse> GetApplicationResponsesForSection(ApplicationResponseCommentManager commentManager, ApplicationSectionResponse section,
                                                                            string updatedBy, int?roleId, ComplianceApplication complianceApplication, ApplicationResponseStatus rfiCompletedStatus, Application application,
                                                                            ApplicationResponseStatus rfiStatus, bool isNonInspector, List <User> orgUsers)
        {
            LogMessage("GetApplicationResponsesForSection (ApplicationManager)");

            var    applicationResponses = new List <ApplicationResponse>();
            string rfiCreatedBy         = string.Empty;

            foreach (var question in section.Questions)
            {
                if (question.IsHidden)
                {
                    continue; //TFS:1295
                }
                //if (roleId != (int) Constants.Role.User && string.IsNullOrEmpty(question.RFICreatedBy))
                //{
                //    rfiCreatedBy = updatedBy;
                //}

                int?statusId      = null;
                int?visibleStatus = null;

                if (question.AnswerResponseStatusId != 0)
                {
                    statusId      = question.AnswerResponseStatusId;
                    visibleStatus = question.AnswerResponseStatusId;
                }

                if (rfiStatus != null && application != null && application.ApplicationStatus.Name != Constants.ApplicationStatus.RFI && statusId == rfiStatus.Id)
                {
                    visibleStatus = null;
                }

                if ((question.Type != "Radio Buttons") && (question.Type != "Checkboxes")) //TFS:1295 - This check prevents saving NULL against appsecquesanswerid in case of radio/checkboxes.
                {
                    if ((question.AnswerResponseStatusName == Constants.ApplicationResponseStatus.NoResponseRequested || !string.IsNullOrEmpty(question.Comments)) && question.QuestionResponses.Count == 0)
                    {
                        var applicationResponse = new ApplicationResponse
                        {
                            ApplicationSectionQuestionId = question.Id.Value,
                            Flag = question.Flag,
                            ApplicationResponseStatusId        = statusId,
                            VisibleApplicationResponseStatusId = visibleStatus,
                            Comments               = question.Comments,
                            CommentLastUpdatedBy   = question.CommentLastUpdatedBy,
                            CommentLastUpdatedDate = question.CommentDate,
                            ApplicationId          = application.Id,
                            CreatedDate            = DateTime.Now,
                            CreatedBy              = updatedBy,
                        };

                        applicationResponses.Add(applicationResponse);
                    }
                    else
                    {
                        foreach (var response in question.QuestionResponses)
                        {
                            var hasResponse         = question.Flag || !string.IsNullOrEmpty(question.Comments);
                            var applicationResponse = new ApplicationResponse
                            {
                                ApplicationSectionQuestionId = question.Id.Value,
                                Flag = question.Flag,
                                ApplicationResponseStatusId        = statusId,
                                VisibleApplicationResponseStatusId = visibleStatus,
                                Comments               = question.Comments,
                                CommentLastUpdatedBy   = question.CommentLastUpdatedBy,
                                CommentLastUpdatedDate = question.CommentDate,
                                ApplicationId          = application.Id,
                                CreatedDate            = DateTime.Now,
                                CreatedBy              = updatedBy,
                            };

                            if (!string.IsNullOrEmpty(response.OtherText))
                            {
                                applicationResponse.Text = response.OtherText;
                                hasResponse = true;
                            }

                            if (!string.IsNullOrEmpty(response.FromDate))
                            {
                                applicationResponse.Text = string.Format("{0} - {1}", response.FromDate, response.ToDate);
                                hasResponse = true;
                            }

                            if (response.UserId.HasValue)
                            {
                                applicationResponse.UserId = response.UserId;
                                hasResponse = true;
                            }

                            if (response.Document != null)
                            {
                                applicationResponse.DocumentId = response.Document.Id;
                                hasResponse = true;
                            }

                            if (hasResponse)
                            {
                                applicationResponses.Add(applicationResponse);
                            }

                            var statusDate = complianceApplication?.Applications?.Max(x => x.UpdatedDate.GetValueOrDefault()) ?? application?.UpdatedDate.GetValueOrDefault();

                            var status = complianceApplication?.ApplicationStatus.Name ?? application?.ApplicationStatus.Name;

                            if (roleId != (int)Constants.Role.FACTAdministrator &&
                                roleId != (int)Constants.Role.FACTCoordinator &&
                                roleId != (int)Constants.Role.QualityManager &&
                                rfiCompletedStatus != null && application != null &&
                                (status == Constants.ApplicationStatus.RFI ||
                                 status == Constants.ApplicationStatus.ApplicantResponse ||
                                 application.ApplicationStatus.Name.Contains("Committee") ||
                                 status == Constants.ApplicationStatus.Complete) &&
                                question.AnswerResponseStatusName == Constants.ApplicationResponseStatus.RFI)
                            {
                                var comments =
                                    commentManager.GetByApplicationIdQuestionId(application.Id,
                                                                                applicationResponse.ApplicationSectionQuestionId);

                                var userComments = comments.Where(
                                    x =>
                                    Convert.ToDateTime(x.CreatedDate) > statusDate &&
                                    x.CommentFrom.Role.Id !=
                                    (int)Constants.Role.FACTAdministrator &&
                                    x.CommentFrom.Role.Id != (int)Constants.Role.FACTCoordinator &&
                                    x.CommentFrom.Role.Id != (int)Constants.Role.QualityManager &&
                                    (x.CommentFrom.Role.Id != (int)Constants.Role.Inspector || orgUsers.Any(y => y.Id == x.FromUser.GetValueOrDefault())))
                                                   .ToList() ?? new List <ApplicationResponseComment>();

                                var maxUserDate = userComments.Select(x => x.CreatedDate).Max();

                                var maxFactDate =
                                    question.ApplicationResponseComments.Where(
                                        x => x.CommentFrom.Role.RoleId == (int)Constants.Role.FACTAdministrator ||
                                        x.CommentFrom.Role.RoleId == (int)Constants.Role.FACTCoordinator ||
                                        x.CommentFrom.Role.RoleId == (int)Constants.Role.QualityManager ||
                                        (x.CommentFrom.Role.RoleId == (int)Constants.Role.Inspector &&
                                         orgUsers.All(y => y.Id != x.FromUser.GetValueOrDefault())))
                                    .Select(x => x.CreatedDate)
                                    .Max();

                                if (Convert.ToDateTime(maxUserDate) > Convert.ToDateTime(maxFactDate) || (maxUserDate.HasValue && string.IsNullOrEmpty(maxFactDate)))
                                {
                                    applicationResponse.ApplicationResponseStatusId        = rfiCompletedStatus.Id;
                                    applicationResponse.VisibleApplicationResponseStatusId = rfiCompletedStatus.Id;
                                }
                            }
                        }
                    }
                }

                if (question.Answers.Count > 0)
                {
                    //TFS:1497
                    var statusDate = application?.UpdatedDate.GetValueOrDefault();
                    var status     = complianceApplication?.ApplicationStatus.Name ?? application?.ApplicationStatus.Name;

                    if (roleId != (int)Constants.Role.FACTAdministrator &&
                        roleId != (int)Constants.Role.FACTCoordinator &&
                        roleId != (int)Constants.Role.QualityManager &&
                        rfiCompletedStatus != null && application != null &&
                        (status == Constants.ApplicationStatus.RFI ||
                         status == Constants.ApplicationStatus.ApplicantResponse ||
                         status == Constants.ApplicationStatus.Complete ||
                         status.Contains("Committee") ||
                         application.ApplicationStatus.Name == Constants.ApplicationStatus.RFI ||
                         application.ApplicationStatus.Name == Constants.ApplicationStatus.ApplicantResponse ||
                         application.ApplicationStatus.Name == Constants.ApplicationStatus.Complete ||
                         application.ApplicationStatus.Name.Contains("Committee")) &&
                        question.AnswerResponseStatusName == Constants.ApplicationResponseStatus.RFI)
                    {
                        var comments =
                            commentManager.GetByApplicationIdQuestionId(application.Id,
                                                                        question.Id.GetValueOrDefault());

                        var userComments = comments.Where(
                            x =>
                            Convert.ToDateTime(x.CreatedDate) > statusDate &&
                            x.CommentFrom.Role.Id != (int)Constants.Role.FACTAdministrator &&
                            x.CommentFrom.Role.Id != (int)Constants.Role.FACTCoordinator &&
                            x.CommentFrom.Role.Id != (int)Constants.Role.QualityManager &&
                            (x.CommentFrom.Role.Id != (int)Constants.Role.Inspector || orgUsers.Any(y => y.Id == x.FromUser.GetValueOrDefault()))).ToList() ?? new List <ApplicationResponseComment>();

                        var maxUserDate = userComments.Select(x => x.CreatedDate).Max();

                        var maxFactDate =
                            question.ApplicationResponseComments.Where(
                                x => x.CommentFrom.Role.RoleId == (int)Constants.Role.FACTAdministrator ||
                                x.CommentFrom.Role.RoleId == (int)Constants.Role.FACTCoordinator ||
                                x.CommentFrom.Role.RoleId == (int)Constants.Role.QualityManager ||
                                (x.CommentFrom.Role.RoleId == (int)Constants.Role.Inspector &&
                                 orgUsers.All(y => y.Id != x.FromUser.GetValueOrDefault())))
                            .Select(x => x.CreatedDate)
                            .Max();

                        if (Convert.ToDateTime(maxUserDate) > Convert.ToDateTime(maxFactDate) || (maxUserDate.HasValue && string.IsNullOrEmpty(maxFactDate)))
                        {
                            statusId      = rfiCompletedStatus.Id;
                            visibleStatus = rfiCompletedStatus.Id;
                        }
                    }

                    var answers = question.Answers
                                  .Where(x => x.Selected)
                                  .Select(answer => new ApplicationResponse
                    {
                        ApplicationSectionQuestionId       = question.Id.Value,
                        ApplicationSectionQuestionAnswerId = answer.Id,        //TFS:1295 - This should handle the Checkboxes responses
                        Flag = question.Flag,
                        //Text = answer.Text, //TFS:1295 - Handles the Checkboxes responses
                        ApplicationResponseStatusId        = statusId,
                        VisibleApplicationResponseStatusId = visibleStatus,
                        Comments               = question.Comments,
                        CommentLastUpdatedBy   = question.CommentLastUpdatedBy,
                        CommentLastUpdatedDate = question.CommentDate,
                        CreatedDate            = DateTime.Now,
                        CreatedBy              = updatedBy
                    })
                                  .ToList();

                    if (answers.Count > 0)
                    {
                        applicationResponses.AddRange(answers);
                    }
                    else if (question.AnswerResponseStatusName == Constants.ApplicationResponseStatus.NoResponseRequested || question.Flag || !string.IsNullOrEmpty(question.Comments))
                    {
                        var applicationResponse = new ApplicationResponse
                        {
                            ApplicationSectionQuestionId = question.Id.Value,
                            Flag = question.Flag,
                            ApplicationResponseStatusId        = statusId,
                            VisibleApplicationResponseStatusId = visibleStatus,
                            Comments               = question.Comments,
                            CommentLastUpdatedBy   = question.CommentLastUpdatedBy,
                            CommentLastUpdatedDate = question.CommentDate,
                            ApplicationId          = application.Id,
                            CreatedDate            = DateTime.Now,
                            CreatedBy              = updatedBy,
                        };

                        applicationResponses.Add(applicationResponse);
                    }
                }
            }

            //TFS: 1610. The following code was commented to fix 1610
            //if (section.Children != null && section.Children.Count > 0)
            //{
            //    applicationResponses.AddRange(this.GetApplicationResponses(section.Children, updatedBy, roleId));
            //}

            return(applicationResponses);
        }
Ejemplo n.º 3
0
 public ApplicationResponse(T value, ApplicationResponseStatus status)
 {
     this.Value  = value;
     this.Status = status;
 }