Ejemplo n.º 1
0
        public async Task ApproveTenderByUnitManagerAsync(string tenderIdString, string verificationCode)
        {
            int tenderId = Util.Decrypt(tenderIdString);
            await _verification.CheckForVerificationCode(tenderId, verificationCode, (int)Enums.VerificationType.Tender);

            Tender tender = await _tenderQueries.FindTenderWithUnitHistoryById(tenderId);

            _tenderDomainService.IsValidToUpdateApproveTenderByUnitManager(tender);
            TenderUnitStatusesHistory tenderUnitStatusesHistory = new TenderUnitStatusesHistory(comment: "", tenderUnitStatusId: (int)Enums.TenderUnitStatus.ApprovedByManager, estimatedValue: tender.EstimatedValue);

            tender.TenderUnitStatusesHistories.Add(tenderUnitStatusesHistory);
            tender.SetUnitStatus(Enums.TenderUnitStatus.ApprovedByManager);
            #region [Send Notification]
            NotificationArguments NotificationArguments = new NotificationArguments
            {
                BodyEmailArgs    = new object[] { tender.ReferenceNumber },
                SubjectEmailArgs = new object[] { },
                PanelArgs        = new object[] { tender.ReferenceNumber },
                SMSArgs          = new object[] { tender.ReferenceNumber }
            };
            MainNotificationTemplateModel mainNotificationTemplateModel = new MainNotificationTemplateModel(NotificationArguments,
                                                                                                            $"Tender/Details?STenderId={Util.Encrypt(tender.TenderId)}",
                                                                                                            NotificationEntityType.Tender,
                                                                                                            tender.TenderId.ToString(),
                                                                                                            tender.BranchId);
            #endregion
            if (tender.IsUnitSecreteryAccepted.Value)
            {
                tender.UpdateSubmitionDate();
                tender.UpdateTenderStatus(Enums.TenderStatus.Approved, "", _httpContextAccessor.HttpContext.User.UserId(), TenderActions.ApproveTenderByUnitManager);
                #region [Send Notification]
                await _notificationAppService.SendNotificationForBranchUsers(NotificationOperations.DataEntry.OperationsOnTheTender.approveTenderByUnit, tender.BranchId, mainNotificationTemplateModel);

                await _notificationAppService.SendNotificationForBranchUsers(NotificationOperations.Auditor.OperationsOnTheTender.approveTenderByUnit, tender.BranchId, mainNotificationTemplateModel);

                #endregion
                if (tender.Invitations.Any(c => c.IsActive == true && c.StatusId == (int)InvitationStatus.ToBeSent))
                {
                    var suppliers = tender.Invitations.Select(t => new SupplierInvitationModel {
                        CommericalRegisterNo = t.CommericalRegisterNo, TenderId = tender.TenderId
                    }).ToList();
                    await SendInvitationsToUnBlockedSuppliers(suppliers, tender);

                    var UnRegesteredsuppliers = tender.UnRegisteredSuppliersInvitation.Where(x => x.IsActive == true && x.InvitationStatusId == (int)InvitationStatus.ToBeSent).ToList();
                    if (UnRegesteredsuppliers.Count > 0)
                    {
                        tender.UpdateUnregesteredInvitations();
                        var emails    = UnRegesteredsuppliers.Where(t => t.Email != null).Select(x => x.Email).ToList();
                        var mobileNos = UnRegesteredsuppliers.Where(t => t.MobileNo != null).Select(x => x.MobileNo).ToList();
                        await _notificationAppService.SendInvitationByEmail(emails, tender);

                        await _notificationAppService.SendInvitationBySms(mobileNos, tender);
                    }
                }
            }
            else
            {
                var tenderUnitHisories = await _tenderQueries.GetUnitStatusesHistoryByTenderId(tenderId);

                tender.UpdateTenderStatus(
                    Enums.TenderStatus.RejectedFromUnit,
                    tenderUnitHisories.OrderByDescending(t => t.TenderUnitStatusesHistoryId).FirstOrDefault().Comment,
                    _httpContextAccessor.HttpContext.User.UserId(),
                    TenderActions.RejectedFromUnit);
                #region [Send Notification]
                await _notificationAppService.SendNotificationForBranchUsers(NotificationOperations.DataEntry.OperationsOnTheTender.rejectTenderByUnit, tender.BranchId, mainNotificationTemplateModel);

                await _notificationAppService.SendNotificationForBranchUsers(NotificationOperations.Auditor.OperationsOnTheTender.rejectTenderByUnit, tender.BranchId, mainNotificationTemplateModel);

                #endregion
            }
            await _tenderCommands.UpdateAsync(tender);
        }