public async Task <ServiceResponse <ApplicationSectionItem> > Save(ApplicationSectionItem model)
        {
            var startTime = DateTime.Now;

            if (base.RoleId == (int)Constants.Role.FACTAdministrator || base.RoleId == (int)Constants.Role.PrimaryContact || base.RoleId == (int)Constants.Role.QualityManager)
            {
                try
                {
                    var facade = this.Container.GetInstance <RequirementFacade>();

                    var section = await facade.SaveAsync(model, base.Email);

                    base.LogMessage("Requirement/Save", DateTime.Now - startTime);

                    this.SendInvalidation();

                    return(new ServiceResponse <ApplicationSectionItem>
                    {
                        Item = ModelConversions.Convert(section, model.AppUniqueId)
                    });
                }
                catch (Exception ex)
                {
                    return(base.HandleException <ApplicationSectionItem>(ex));
                }
            }
            else
            {
                return(new ServiceResponse <ApplicationSectionItem>
                {
                    HasError = true,
                    Message = "Not Authorized"
                });
            }
        }
        public async Task <ApplicationSection> SaveAsync(ApplicationSectionItem item, string updatedBy)
        {
            var applicationSectionManager   = this.container.GetInstance <ApplicationSectionManager>();
            var applicationTypeManager      = this.container.GetInstance <ApplicationTypeManager>();
            var applicationSectionScopeType = this.container.GetInstance <ApplicationSectionScopeTypeManager>();
            var applicationVersionManager   = this.container.GetInstance <ApplicationVersionManager>();

            var applicationType = await applicationTypeManager.GetByNameAsync(item.ApplicationTypeName);

            if (applicationType == null)
            {
                throw new ObjectNotFoundException("Can't find Application Type");
            }

            var version = applicationVersionManager.GetById(item.VersionId.GetValueOrDefault());

            var applicationSection = await applicationSectionManager.AddOrUpdateAsync(applicationType, item, updatedBy);

            await applicationSectionScopeType.UpdateApplicationSectionScopeTypeAsync(item, updatedBy, applicationSection.Id);

            if (item.Id != null)
            {
                return(applicationSection);
            }

            await applicationVersionManager.CheckVersionNumberAsync(version, item.Version, updatedBy);

            return(applicationSection);
        }
        public async Task UpdateApplicationSectionScopeTypeAsync(ApplicationSectionItem applicationSectionItem, string updatedBy, Guid?applicationSectionId)
        {
            LogMessage("RemoveItems (ApplicationSectionScopeTypeManager)");

            if (applicationSectionItem.Id.HasValue)
            {
                var existingScopetypes = base.Repository.GetAllByApplicationSectionIdAsync(applicationSectionItem.Id).Result;

                foreach (var item in existingScopetypes)
                {
                    base.BatchRemove(item);
                }

                var scopeTypes = applicationSectionItem.ScopeTypes.Where(x => x.IsSelected == true).ToList();

                foreach (var objectScopeType in scopeTypes)
                {
                    ApplicationSectionScopeType applicationSectionScopeType = new ApplicationSectionScopeType();
                    applicationSectionScopeType.Id                   = Guid.NewGuid();
                    applicationSectionScopeType.ScopeTypeId          = objectScopeType.ScopeTypeId;
                    applicationSectionScopeType.ApplicationSectionId = applicationSectionItem.Id.GetValueOrDefault();
                    applicationSectionScopeType.IsActual             = false;
                    applicationSectionScopeType.IsDefault            = true;
                    applicationSectionScopeType.CreatedBy            = updatedBy;
                    applicationSectionScopeType.CreatedDate          = DateTime.Now;
                    applicationSectionScopeType.UpdatedBy            = updatedBy;
                    applicationSectionScopeType.UpdatedDate          = DateTime.Now;

                    base.BatchAdd(applicationSectionScopeType);
                }
                await base.Repository.SaveChangesAsync();
            }
            else
            {
                var scopeTypes = applicationSectionItem.ScopeTypes.Where(x => x.IsSelected == true).ToList();

                foreach (var objectScopeType in scopeTypes)
                {
                    ApplicationSectionScopeType applicationSectionScopeType = new ApplicationSectionScopeType();
                    applicationSectionScopeType.Id                   = Guid.NewGuid();
                    applicationSectionScopeType.ScopeTypeId          = objectScopeType.ScopeTypeId;
                    applicationSectionScopeType.ApplicationSectionId = applicationSectionId.GetValueOrDefault();
                    applicationSectionScopeType.IsActual             = false;
                    applicationSectionScopeType.IsDefault            = true;
                    applicationSectionScopeType.CreatedBy            = updatedBy;
                    applicationSectionScopeType.CreatedDate          = DateTime.Now;
                    base.BatchAdd(applicationSectionScopeType);
                }
                await base.Repository.SaveChangesAsync();
            }
        }
        public void UpdateResponseStatus(ApplicationSectionItem section, int fromStatus, int toStatus, string updatedBy, Guid applicationUniqueId, int applicationId)
        {
            LogMessage("UpdateResponseStatus (ApplicationResponseTraineeManager)");

            var traineeResponses = this.GetApplicationResponses(applicationUniqueId);

            foreach (var question in section.Questions.Where(x => x.Id != null))
            {
                var savedResponses = traineeResponses.Where(x => x.ApplicationSectionQuestionId == question.Id).ToList();

                if (savedResponses.Count == 0 && fromStatus == (int)Constants.ApplicationResponseStatuses.Reviewed)
                {
                    var actualResponses = this.applicationResponseManager.GetResponsesByAppIdQuestionId(question.Id, applicationId);

                    foreach (var actualResponse in actualResponses)
                    {
                        var resp = new ApplicationResponseTrainee
                        {
                            ApplicationId = applicationId,
                            ApplicationSectionQuestionId = question.Id.Value,
                            ApplicationResponseStatusId  = toStatus,
                            CreatedBy   = updatedBy,
                            CreatedDate = DateTime.Now
                        };

                        this.Repository.Add(resp);
                    }
                }
                else
                {
                    foreach (var questionResponse in savedResponses)
                    {
                        if (questionResponse.ApplicationResponseStatusId == fromStatus)
                        {
                            questionResponse.ApplicationResponseStatusId = toStatus;

                            this.Repository.Save(questionResponse);
                        }
                    }
                }
            }
        }
示例#5
0
        public void UpdateResponseStatus(ApplicationSectionItem section, int fromStatus, int toStatus, string updatedBy, int applicationId)
        {
            LogMessage("UpdateResponseStatus (ApplicationResponseManager)");

            foreach (var question in section.Questions)
            {
                var savedResponses = this.GetResponsesByAppIdQuestionId(question.Id, applicationId);
                foreach (var questionResponse in savedResponses)
                {
                    if ((questionResponse.ApplicationResponseStatusId == null && fromStatus == (int)Constants.ApplicationResponseStatuses.ForReview) || questionResponse.ApplicationResponseStatusId == fromStatus)
                    {
                        var response = this.Repository.GetById(questionResponse.Id);
                        response.ApplicationResponseStatusId = toStatus;
                        response.UpdatedBy   = updatedBy;
                        response.UpdatedDate = DateTime.Now;

                        this.Repository.Save(response);
                    }
                }
            }
        }
示例#6
0
        public List <ApplicationResponseTrainee> GetApplicationResponsesTraineeForSection(ApplicationSectionItem section, string updatedBy, int?roleId)
        {
            LogMessage("GetApplicationResponsesTraineeForSection (ApplicationManager)");

            var    applicationResponsesTrainee = new List <ApplicationResponseTrainee>();
            string rfiCreatedBy = string.Empty;

            foreach (var question in section.Questions)
            {
                int statusId = 0;

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

                foreach (var response in question.QuestionResponses)
                {
                    var hasResponse = false;
                    var applicationResponseTrainee = new ApplicationResponseTrainee
                    {
                        ApplicationSectionQuestionId = question.Id.Value,
                        ApplicationResponseStatusId  = statusId,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = updatedBy,
                    };

                    if (hasResponse)
                    {
                        applicationResponsesTrainee.Add(applicationResponseTrainee);
                    }
                }

                if (question.Answers.Count > 0)
                {
                    applicationResponsesTrainee.AddRange(
                        question.Answers
                        .Where(x => x.Selected)
                        .Select(answer => new ApplicationResponseTrainee
                    {
                        ApplicationSectionQuestionId       = question.Id.Value,
                        ApplicationSectionQuestionAnswerId = answer.Id,
                        ApplicationResponseStatusId        = statusId,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = updatedBy
                    }));
                }
            }

            if (section.Children != null && section.Children.Count > 0)
            {
                applicationResponsesTrainee.AddRange(this.GetApplicationResponsesTrainee(section.Children, updatedBy, roleId));
            }

            return(applicationResponsesTrainee);
        }