Esempio n. 1
0
        public CommentsModel GetCommentsModel(int id, RequestTypeEnum typeId)
        {
            CommentsModel commentModel = new CommentsModel
            {
                RequestId = id,
                RequestTypeId = (int)typeId,
                Comments = new List<RequestCommentModel>(),
                IsAddAvailable = /*AuthenticationService.CurrentUser.UserRole == UserRole.PersonnelManager &&*/ id > 0,
            };
            if (id == 0)
                return commentModel;
             switch (typeId)
             {
                 case RequestTypeEnum.Appointment:
                     Appointment entity = AppointmentDao.Load(id);
                     if ((entity.Comments != null) && (entity.Comments.Count() > 0))
                     {
                         commentModel.Comments = entity.Comments.OrderBy(x => x.DateCreated).ToList().
                             ConvertAll(x => new RequestCommentModel
                                                 {
                                                     Comment = x.Comment,
                                                     CreatedDate = x.DateCreated.ToString(),
                                                     Creator = x.User.FullName,
                                                 });
                     }
                     break;
                 case RequestTypeEnum.AppointmentReport:
                     AppointmentReport rep = AppointmentReportDao.Load(id);
                     if ((rep.Comments != null) && (rep.Comments.Count() > 0))
                     {
                         commentModel.Comments = rep.Comments.OrderBy(x => x.DateCreated).ToList().
                             ConvertAll(x => new RequestCommentModel
                             {
                                 Comment = x.Comment,
                                 CreatedDate = x.DateCreated.ToString(),
                                 Creator = x.User.FullName,
                             });
                     }
                     break;
                 default:
                     throw new ValidationException(string.Format(StrInvalidCommentType, (int)typeId));

            }
            return commentModel;
            //Vacation vacation = VacationDao.Load(id);
        }
Esempio n. 2
0
        public CommentsModel GetCommentsModel(int id, RequestTypeEnum typeId)
        {
            bool isAddAvailable = id > 0;
            if (isAddAvailable)
            {
                if (typeId == RequestTypeEnum.HelpServiceRequest)
                {
                    HelpServiceRequest request = HelpServiceRequestDao.Load(id);
                    isAddAvailable =  (((CurrentUser.Id == request.Creator.Id) &&
                                        ((CurrentUser.UserRole & UserRole.Manager) == UserRole.Manager || (CurrentUser.UserRole & UserRole.ConsultantPersonnel) == UserRole.ConsultantPersonnel || (CurrentUser.UserRole & UserRole.Employee) == UserRole.Employee)) ||
                                        (request.Consultant != null &&
                                            CurrentUser.Id == request.Consultant.Id &&
                                            CurrentUser.UserRole == UserRole.ConsultantOutsourcing) ||
                                         (request.Consultant != null &&
                                            CurrentUser.Id == request.Consultant.Id &&
                                            CurrentUser.UserRole == UserRole.PersonnelManager) ||
                                         (request.Consultant != null &&
                                            CurrentUser.Id == request.Consultant.Id &&
                                            CurrentUser.UserRole == UserRole.ConsultantPersonnel)
                                        );
                }
            }
            CommentsModel commentModel = new CommentsModel
            {
                RequestId = id,
                RequestTypeId = (int)typeId,
                Comments = new List<RequestCommentModel>(),
                IsAddAvailable = isAddAvailable ,
            };
            if (id == 0)
                return commentModel;
            switch (typeId)
            {
                case RequestTypeEnum.HelpServiceRequest:
                    HelpServiceRequest entity = HelpServiceRequestDao.Load(id);
                    if ((entity.Comments != null) && (entity.Comments.Count() > 0))
                    {
                        commentModel.Comments = entity.Comments.OrderBy(x => x.DateCreated).ToList().
                            ConvertAll(x => new RequestCommentModel
                            {
                                Comment = x.Comment,
                                CreatedDate = x.DateCreated.ToString(),
                                Creator = x.User.FullName,
                            });
                    }
                    break;
                default:
                    throw new ValidationException(string.Format(AppointmentBl.StrInvalidCommentType, (int)typeId));

            }
            return commentModel;
        }