Пример #1
0
 private void SendCarrResponsedEmailToAreaAdministrator(BOCANotificationViewModel bocaNotificationViewModel)
 {
     if (bocaNotificationViewModel != null)
     {
         var emailRequest = new EmailRequest <BOCANotificationViewModel>()
         {
             Model = bocaNotificationViewModel
         };
         emailRequest.To.Add(new System.Net.Mail.MailAddress(bocaNotificationViewModel.ToEmail));
         _emailComposer.SendBOCAEmails(emailRequest, EmailTemplate.CarrResponsed, $"MBOS: Report for CARR with Reference No: {bocaNotificationViewModel.CARRReferenceNo}");
     }
 }
Пример #2
0
 private void SendCarrRequestedEmailsToBranchOicUser(BOCANotificationViewModel bocaNotificationViewModel)
 {
     if (bocaNotificationViewModel != null)
     {
         var emailRequest = new EmailRequest <BOCANotificationViewModel>()
         {
             Model = bocaNotificationViewModel
         };
         emailRequest.To.Add(new System.Net.Mail.MailAddress(bocaNotificationViewModel.ToEmail));
         _emailComposer.SendBOCAEmails(emailRequest, EmailTemplate.CarrRequested, $"MBOS: CARR(s) for Assessment No: {bocaNotificationViewModel.AssessmentNo}");
     }
 }
Пример #3
0
 private void SendCarrResponseVerifiedEmailToBranchOicUser(BOCANotificationViewModel bocaNotificationViewModel)
 {
     if (bocaNotificationViewModel != null)
     {
         var emailRequest = new EmailRequest <BOCANotificationViewModel>()
         {
             Model = bocaNotificationViewModel
         };
         emailRequest.To.Add(new System.Net.Mail.MailAddress(bocaNotificationViewModel.ToEmail));
         //string carrVerifyReject = bocaNotificationViewModel.CARRResponseStatus == CARRResponseStatus.NotSatisfactory ? "Rejected" : bocaNotificationViewModel.CARRResponseStatus == CARRResponseStatus.Satisfactory ? "Verified" : "Done";
         _emailComposer.SendBOCAEmails(emailRequest, EmailTemplate.CarrResponseVerified, $"MBOS: CARR with reference no: {bocaNotificationViewModel.CARRReferenceNo} {bocaNotificationViewModel.VerifiedRejected} ");
     }
 }
Пример #4
0
        public BOCAAssessmentViewModel AddBOCAAssessment(ServiceRequestModel <BOCAAssessmentViewModel> serviceRequestModel)
        {
            DateTime assessmentDate;

            DateTime.TryParse(serviceRequestModel.Model.Date, out assessmentDate);

            var monthStartDate = assessmentDate.FirstDayOfMonth();
            var monthEndDate   = assessmentDate.LastDayOfMonth();

            if (assessmentDate.Date > GeneralService.CurrentDate.Date)
            {
                throw new ArgumentNullException($"The assessment date cannot be in future.", innerException: null);
            }
            var assessmentExists = AssessmentRepository.GetAll().Any(c => c.BranchId == serviceRequestModel.Model.BranchId && c.Date >= monthStartDate && c.Date <= monthEndDate);

            if (assessmentExists)
            {
                throw new ArgumentNullException($"BOCA Assessment for the month {assessmentDate.ToString(@"MMM\'yy")} already exists in the system", innerException: null);
            }
            var branchOicUser = _sharedService.GetBranchOICUser(serviceRequestModel.Model.BranchId);

            if (branchOicUser == null)
            {
                throw new ArgumentNullException($"There is no user assigned with role Branch OIC for the branch.", innerException: null);
            }
            var mapped = _mapper.Map <BOCAAssessmentViewModel, BOCAAssessment>(serviceRequestModel.Model);
            //mapped.Id = Guid.NewGuid();   //it is not required as Id is already populated
            var branch     = _setupService.GetBranch(mapped.BranchId);
            var branchAbbr = branch != null ? branch.ShortName : string.Empty;

            if (string.IsNullOrWhiteSpace(branchAbbr))
            {
                throw new ArgumentNullException($"Assessment number could not be generated as Branch Code is not valid", innerException: null);
            }

            var nextBocaRunningNo = _sharedService.GetNextRunningNumber(RunningNumberType.BOCA, mapped.Date.Year, branchAbbr);

            if (nextBocaRunningNo == 0)
            {
                throw new ArgumentNullException($"Error while generating the Assessment Number", innerException: null);
            }

            mapped.AssessmentNo    = $"{"BOCA"}/{mapped.Date.Year}-{branchAbbr}-{nextBocaRunningNo.ToString().PadLeft(3, '0')}";
            mapped.AssessorId      = serviceRequestModel.LoginInfo.UserId;
            mapped.BranchOICUserId = branchOicUser.Id;
            mapped.Status          = AssessmentStatus.Open;

            mapped.CreatedDate = GeneralService.CurrentDate;
            if (!serviceRequestModel.Model.IsPartialSave)
            {
                mapped.Status      = serviceRequestModel.Model.ChecklistCriteria.SelectMany(x => x.BOCAChecklist).Where(x => x.CARRRequest != null).Select(x => x.CARRRequest).Any() ? AssessmentStatus.Open : AssessmentStatus.Closed;
                mapped.IsCompleted = true;
            }

            AssessmentRepository.Add(mapped);
            var carrCount = 0;

            foreach (var bocaViewModel in serviceRequestModel.Model.ChecklistCriteria.SelectMany(x => x.BOCAChecklist).ToList())
            {
                //bocaViewModel.Id = Guid.NewGuid();
                bocaViewModel.BOCAAssessmentId = mapped.Id;

                var boca = _mapper.Map <BOCAViewModel, BOCA>(bocaViewModel);
                boca.Attachments = null;
                BocaRepository.Add(boca);

                if (bocaViewModel.CARRRequest != null)
                {
                    var nextCarrRunningNo = 0;

                    if (!serviceRequestModel.Model.IsPartialSave)
                    {
                        nextCarrRunningNo = _sharedService.GetNextRunningNumber(RunningNumberType.CARR, mapped.Date.Year, branchAbbr);
                    }

                    var carrReq = _mapper.Map <CARRRequestViewModel, CARRRequest>(bocaViewModel.CARRRequest);
                    var carrId  = Guid.NewGuid();
                    // response for partial save
                    bocaViewModel.CARRRequest.Id = carrId;
                    carrReq.Id     = carrId;
                    carrReq.BOCAId = boca.Id;

                    if (!serviceRequestModel.Model.IsPartialSave)
                    {
                        carrReq.ReferenceNo = $"{"BOCA/CARR"}/{mapped.Date.Year}-{branchAbbr}-{nextCarrRunningNo.ToString().PadLeft(3, '0')}";
                    }
                    //carrReq.RecommendedReplyDate = mapped.Date.AddDays(14);
                    carrReq.CARRStatus = CARRStatus.Pending;
                    CarrRequestRepository.Add(carrReq);
                    carrCount++;
                }

                if (bocaViewModel.Attachments.Any())
                {
                    bocaViewModel.Attachments.ForEach(y =>
                    {
                        y.Id               = Guid.NewGuid();
                        y.BOCAId           = boca.Id;
                        var p              = _mapper.Map <BocaAttachmentViewModel, BOCAAttachment>(y);
                        var attachFullName =
                            p.AttachmentFullName.MoveToDestination(serviceRequestModel.Model.HostingEnviromentPath,
                                                                   "BOCA/" + mapped.Id);
                        y.AttachmentFullName = attachFullName;
                        p.AttachmentFullName = attachFullName;

                        AttachmentRepository.Add(p);
                    });
                }
            }

            _genericUnitOfWork.SaveChanges();

            if (serviceRequestModel.Model.IsPartialSave)
            {
                serviceRequestModel.Model.AssessmentNo = mapped.AssessmentNo;
                return(serviceRequestModel.Model);
            }
            if (carrCount == 0)
            {
                return(new BOCAAssessmentViewModel());
            }

            var bocaNotificationViewModel = new BOCANotificationViewModel
            {
                AssessmentNo     = mapped.AssessmentNo,
                CARRRequestCount = carrCount,
                ToEmail          = branchOicUser.Email
            };

            SendCarrRequestedEmailsToBranchOicUser(bocaNotificationViewModel);

            return(new BOCAAssessmentViewModel());
        }
Пример #5
0
        public void UpdateCARRRequest(ServiceRequestModel <CARRRequestViewModel> serviceRequestModel)
        {
            var carrRequestEntity = CarrRequestRepository.GetById(serviceRequestModel.Model.Id);

            #region Update done by AA/AAA
            if (GeneralService.IsAreaAdministratorRole(serviceRequestModel.LoginInfo.RoleId))
            {
                if (serviceRequestModel.Model.PreviousResponses.Any())
                {
                    var resp       = serviceRequestModel.Model.PreviousResponses.Last();
                    var respEntity = CarrResponseRepository.GetById(resp.Id);

                    if (respEntity != null)
                    {
                        respEntity.CARRResponseStatus = resp.CARRResponseStatus;
                        CarrResponseRepository.Update(respEntity);


                        if (!string.IsNullOrEmpty(resp.RecommendedReplyDate) && resp.CARRResponseStatus != CARRStatus.Closed)
                        {
                            carrRequestEntity.RecommendedReplyDate = resp.RecommendedReplyDate.ToStringDate();
                        }

                        carrRequestEntity.CARRStatus = resp.CARRResponseStatus;
                        CarrRequestRepository.Update(carrRequestEntity);

                        var branchOicUser = _sharedService.GetBranchOICUser(serviceRequestModel.Model.BranchId);
                        if (branchOicUser != null)
                        {
                            var bocaNotificationViewModel = new BOCANotificationViewModel
                            {
                                CARRReferenceNo    = serviceRequestModel.Model.ReferenceNo,
                                CARRResponseStatus = resp.CARRResponseStatus,
                                ToEmail            = branchOicUser.Email,
                                AssessmentNo       = carrRequestEntity.BOCA.BOCAAssessment.AssessmentNo
                            };

                            SendCarrResponseVerifiedEmailToBranchOicUser(bocaNotificationViewModel);
                        }

                        _genericUnitOfWork.SaveChanges();
                    }


                    if (resp.CARRResponseStatus == CARRStatus.Closed)
                    {
                        if (carrRequestEntity != null)
                        {
                            //  carrRequestEntity.CARRStatus = CARRStatus.Closed;
                            //   CarrRequestRepository.Update(carrRequestEntity);


                            var assessment     = AssessmentRepository.GetAll().FirstOrDefault(x => x.AssessmentNo == serviceRequestModel.Model.AssessmentNo);
                            var carrsQueryable = CarrRequestRepository.GetAll().Where(car => car.BOCA.BOCAAssessment.Id == assessment.Id);

                            if (assessment != null && carrsQueryable.Count() == carrsQueryable.Count(c => c.CARRStatus == CARRStatus.Closed))
                            {
                                assessment.Status = AssessmentStatus.Closed;
                                AssessmentRepository.Update(assessment);
                            }


                            _genericUnitOfWork.SaveChanges();
                        }
                    }
                }
            }
            #endregion

            #region Update done by BranchOIC

            if (serviceRequestModel.Model.CurrentResponse == null ||
                serviceRequestModel.LoginInfo.RoleId != new Guid(ApplicationConstants.BranchOICRoleId))
            {
                return;
            }

            var mappedResponse = _mapper.Map <CARRResponseViewModel, CARRResponse>(serviceRequestModel.Model.CurrentResponse);
            mappedResponse.Id                 = Guid.NewGuid();
            mappedResponse.CARRRequestId      = serviceRequestModel.Model.Id;
            mappedResponse.CARRResponseStatus = CARRStatus.Submitted;
            mappedResponse.CARRResponseDate   = GeneralService.CurrentDate;
            CarrResponseRepository.Add(mappedResponse);
            _genericUnitOfWork.SaveChanges();


            carrRequestEntity.CARRStatus = CARRStatus.Submitted;
            CarrRequestRepository.Update(carrRequestEntity);
            _genericUnitOfWork.SaveChanges();

            var areaAdminUser = _setupService.GetUserByuserId(serviceRequestModel.Model.AssessorId);
            if (areaAdminUser == null)
            {
                return;
            }


            var notificationViewModel = new BOCANotificationViewModel
            {
                CARRReferenceNo    = serviceRequestModel.Model.ReferenceNo,
                CARRResponseStatus = mappedResponse.CARRResponseStatus,
                ToEmail            = areaAdminUser.Email,
                AssessmentNo       = carrRequestEntity.BOCA.BOCAAssessment.AssessmentNo
            };
            SendCarrResponsedEmailToAreaAdministrator(notificationViewModel);


            #endregion
        }
Пример #6
0
        public BOCAAssessmentViewModel UpdateBOCAAssessment(ServiceRequestModel <BOCAAssessmentViewModel> serviceRequestModel)
        {
            var branchOicUser = _sharedService.GetBranchOICUser(serviceRequestModel.Model.BranchId);

            if (branchOicUser == null)
            {
                throw new ArgumentNullException($"There is no user assigned with role Branch OIC for the branch.", innerException: null);
            }



            var carrCount = 0;

            var assessmentDb = AssessmentRepository.GetById(serviceRequestModel.Model.Id);


            if (!serviceRequestModel.Model.IsPartialSave)
            {
                assessmentDb.IsCompleted = true;
                assessmentDb.CreatedDate = GeneralService.CurrentDate;
                assessmentDb.Status      =
                    serviceRequestModel.Model.ChecklistCriteria.SelectMany(x => x.BOCAChecklist)
                    .Where(x => x.CARRRequest != null)
                    .Select(x => x.CARRRequest)
                    .Any()
                        ? AssessmentStatus.Open
                        : AssessmentStatus.Closed;

                AssessmentRepository.Update(assessmentDb);
            }



            var branchCode = branchOicUser.UserBranches.FirstOrDefault()?.Branch.ShortName;

            serviceRequestModel.Model.ChecklistCriteria.SelectMany(x => x.BOCAChecklist).ToList().ForEach(x =>
            {
                var boca = _mapper.Map <BOCAViewModel, BOCA>(x);
                boca.BOCAAssessmentId = assessmentDb.Id;
                boca.Attachments      = null;
                BocaRepository.AddOrUpdate(boca);

                x.Id = boca.Id;

                var carr = CarrRequestRepository.GetAll().FirstOrDefault(p => p.BOCAId == boca.Id);

                if (carr != null)
                {
                    CarrRequestRepository.Delete(carr);
                }

                if (x.ScoringGuideId > 2)
                {
                    x.CARRRequest = null;
                }

                if (x.CARRRequest != null)
                {
                    if (!serviceRequestModel.Model.IsPartialSave)
                    {
                        var nextCarrRunningNo = _sharedService.GetNextRunningNumber(RunningNumberType.CARR,
                                                                                    assessmentDb.Date.Year, branchCode);
                        x.CARRRequest.ReferenceNo = $"{"BOCA/CARR"}/{assessmentDb.Date.Year}-{branchCode}-{nextCarrRunningNo.ToString().PadLeft(3, '0')}";
                    }

                    var carrRequest    = _mapper.Map <CARRRequestViewModel, CARRRequest>(x.CARRRequest);
                    carrRequest.BOCAId = boca.Id;
                    //carrRequest.RecommendedReplyDate = serviceRequestModel.Model.Date.ToStringDate().AddDays(14);
                    carrRequest.CARRStatus = CARRStatus.Pending;
                    carrRequest.Id         = Guid.NewGuid();
                    CarrRequestRepository.Add(carrRequest);
                    x.CARRRequest.Id = carrRequest.Id;
                    carrCount++;
                }

                if (x.Attachments.Any())
                {
                    x.Attachments.ForEach(y =>
                    {
                        if (y.Id == Guid.Empty)
                        {
                            y.Id = Guid.NewGuid();
                        }

                        y.BOCAId = boca.Id;

                        var p = _mapper.Map <BocaAttachmentViewModel, BOCAAttachment>(y);
                        var attachmentFullName =
                            p.AttachmentFullName.MoveToDestination(serviceRequestModel.Model.HostingEnviromentPath,
                                                                   "BOCA/" + assessmentDb.Id);
                        p.AttachmentFullName = attachmentFullName;
                        y.AttachmentFullName = attachmentFullName;
                        AttachmentRepository.AddOrUpdate(p);
                    });
                }
                ;
            });

            _genericUnitOfWork.SaveChanges();

            if (serviceRequestModel.Model.IsPartialSave)
            {
                return(serviceRequestModel.Model);
            }

            if (carrCount == 0)
            {
                return(new BOCAAssessmentViewModel());
            }



            var bocaNotificationViewModel = new BOCANotificationViewModel
            {
                AssessmentNo     = assessmentDb.AssessmentNo,
                CARRRequestCount = carrCount,
                ToEmail          = branchOicUser.Email
            };

            SendCarrRequestedEmailsToBranchOicUser(bocaNotificationViewModel);
            return(new BOCAAssessmentViewModel());
        }