Exemple #1
0
        public ServiceResponse <ApplicationResponseCommentItem> Save(ApplicationResponseCommentItem applicationResponseCommentItem)
        {
            DateTime startTime = DateTime.Now;

            try
            {
                var applicationResponseCommentFacade = this.Container.GetInstance <ApplicationResponseCommentFacade>();

                var applicationResponseComment = applicationResponseCommentFacade.Save(applicationResponseCommentItem, base.UserId.GetValueOrDefault(), base.Email);

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

                var manager = this.Container.GetInstance <ApplicationResponseCommentManager>();

                var comment = manager.GetById(applicationResponseComment.Id);

                return(new ServiceResponse <ApplicationResponseCommentItem>()
                {
                    Item = ModelConversions.Convert(comment)
                });
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <ApplicationResponseCommentItem>()
                {
                    HasError = true,
                    Message = ex.Message
                });
            }
        }
Exemple #2
0
        public ServiceResponse SetVisibility(ApplicationResponseCommentItem model)
        {
            DateTime startTime = DateTime.Now;

            try
            {
                var applicationResponseCommentFacade = this.Container.GetInstance <ApplicationResponseCommentFacade>();

                applicationResponseCommentFacade.SetCommentVisibility(model.ApplicationResponseCommentId,
                                                                      model.VisibleToApplicant, base.Email);

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

                return(new ServiceResponse());
            }
            catch (Exception ex)
            {
                return(base.HandleException(ex));
            }
        }
        public ApplicationResponseComment Save(ApplicationResponseCommentItem applicationResponseCommentItem, Guid currentUserId, string createdBy)
        {
            var applicationResponseCommentManager = this.container.GetInstance <ApplicationResponseCommentManager>();
            var commentTypeManager     = this.container.GetInstance <CommentTypeManager>();
            var documentManager        = this.container.GetInstance <DocumentManager>();
            var associationTypeManager = this.container.GetInstance <AssociationTypeManager>();
            var userManager            = this.container.GetInstance <UserManager>();
            var currentUserByEmail     = userManager.GetByEmailAddress(createdBy);
            var currentUser            = currentUserByEmail;

            if (applicationResponseCommentItem.CommentType.Id > 0 && currentUserByEmail.Id != currentUserId)
            {
                currentUser = userManager.GetById(currentUserId);

                var commentType = commentTypeManager.GetById(applicationResponseCommentItem.CommentType.Id);

                if (commentType == null ||
                    (commentType.Name == Constants.CommentTypes.FACTOnly &&
                     currentUserByEmail.Role.Name != Constants.Roles.FACTAdministrator &&
                     currentUserByEmail.Role.Name != Constants.Roles.FACTCoordinator &&
                     currentUserByEmail.Role.Name != Constants.Roles.QualityManager))
                {
                    throw new Exception("Cannot save FACT Only comment");
                }
            }



            ApplicationResponseComment applicationResponseComment = null;

            if (applicationResponseCommentItem.ApplicationResponseCommentId == 0)// new case
            {
                applicationResponseComment = new ApplicationResponseComment
                {
                    QuestionId         = applicationResponseCommentItem.QuestionId,
                    ApplicationId      = applicationResponseCommentItem.ApplicationId,
                    DocumentId         = applicationResponseCommentItem.DocumentId,
                    FromUser           = currentUser.Id,
                    CreatedBy          = createdBy,
                    CreatedDate        = DateTime.Now,
                    UpdatedDate        = DateTime.Now,
                    UpdatedBy          = createdBy,
                    VisibleToApplicant = true,
                    IncludeInReporting = true,
                    Comment            = applicationResponseCommentItem.Comment,
                    CommentTypeId      = applicationResponseCommentItem.CommentType.Id,
                    ApplicationResponseCommentDocuments =
                        applicationResponseCommentItem.CommentDocuments.Select(
                            x => new ApplicationResponseCommentDocument
                    {
                        Id          = Guid.NewGuid(),
                        DocumentId  = x.DocumentId,
                        CreatedBy   = createdBy,
                        CreatedDate = DateTime.Now
                    })
                        .ToList()
                };

                //applicationResponseComment.ToUser = userManager.GetByEmailAddress(createdBy).Id;


                applicationResponseCommentManager.Add(applicationResponseComment);

                applicationResponseComment.CommentFrom = currentUser;
            }
            else //update
            {
                applicationResponseComment = applicationResponseCommentManager.GetById(applicationResponseCommentItem.ApplicationResponseCommentId);


                applicationResponseComment.DocumentId = applicationResponseCommentItem.DocumentId;
                //applicationResponseComment.ToUser = userManager.GetByEmailAddress(createdBy).Id;
                applicationResponseComment.UpdatedDate = DateTime.Now;


                if (currentUserByEmail.Id != applicationResponseComment.FromUser.Value &&
                    (currentUserByEmail.Role.Name == Constants.Roles.FACTAdministrator ||
                     currentUserByEmail.Role.Name == Constants.Roles.FACTCoordinator ||
                     currentUserByEmail.Role.Name == Constants.Roles.QualityManager))
                {
                    applicationResponseComment.CommentOverride = applicationResponseCommentItem.Comment;
                    applicationResponseComment.OverridenBy     = createdBy;
                }
                else
                {
                    applicationResponseComment.FromUser  = userManager.GetByEmailAddress(createdBy).Id;
                    applicationResponseComment.UpdatedBy = createdBy;
                    applicationResponseComment.Comment   = applicationResponseCommentItem.Comment;
                }


                applicationResponseComment.CommentTypeId = applicationResponseCommentItem.CommentType.Id;

                applicationResponseComment.ApplicationResponseCommentDocuments =
                    applicationResponseCommentItem.CommentDocuments.Select(
                        x => new ApplicationResponseCommentDocument
                {
                    Id          = Guid.NewGuid(),
                    DocumentId  = x.DocumentId,
                    CreatedBy   = createdBy,
                    CreatedDate = DateTime.Now
                })
                    .ToList();

                applicationResponseCommentManager.Save(applicationResponseComment);
            }

            var association = associationTypeManager.GetByName(Constants.AssociationTypes.RfiResponse);

            if (applicationResponseCommentItem.DocumentId.HasValue)
            {
                documentManager.UpdateDocumentAssociations(applicationResponseCommentItem.DocumentId.Value, association, createdBy);

                var doc = documentManager.GetById(applicationResponseCommentItem.DocumentId.Value);
                applicationResponseComment.Document = doc;
            }

            if (applicationResponseCommentItem.CommentDocuments != null &&
                applicationResponseCommentItem.CommentDocuments.Count > 0)
            {
                foreach (var doc in applicationResponseCommentItem.CommentDocuments)
                {
                    documentManager.UpdateDocumentAssociations(doc.DocumentId, association, createdBy);
                }
            }

            return(applicationResponseComment);
        }