コード例 #1
0
        public async Task UpdateBidsPhaseDaily()
        {
            IMailService mail = new MailService(MailSettings, MailSecrets);

            /*IMailService mail = new MailService(
             *  new MailSettings() { DisplayName = "UniBuy", Host = "smtp.gmail.com", Mail = "*****@*****.**", Port = 587 },
             *  new MailSecrets() { Password = "******" });
             */
            //YotyContext context = new YotyContext();
            // don't need mapper rn

            using (var scope = ScopeFactory.CreateScope())
            {
                YotyContext context = scope.ServiceProvider.GetRequiredService <YotyContext>();
                try
                {
                    var ids = context.Bids
                              // .Where(bid => bid.Phase<BidPhase.CancelledSupplierNotFound && bid.ExpirationDate < DateTime.UtcNow.AddHours(2))
                              .Select(bid => bid.Id)
                              .ToList();

                    foreach (var id in ids)
                    {
                        using (var scopeForEachBid = ScopeFactory.CreateScope())
                        {
                            Response response = await TryUpdateBidPhaseAndNotify(scopeForEachBid, mail, id).ConfigureAwait(false);

                            Console.WriteLine($"UpdatePhase bidId:{id}, success:{response.IsOperationSucceeded}, message:{response.SuccessOrFailureMessage}");
                        }
                    }
                }

                catch (Exception ex) {
                    Console.WriteLine($"Exception was thrown where trying to attampth context.bids in {nameof(UpdateBidsPhaseDaily)}.\nexception details: {ex}");
                }
                // when we exit the using block,
                // the IServiceScope will dispose itself
                // and dispose all of the services that it resolved.
            }
        }
コード例 #2
0
        public static async Task <Response> TryUpdateBidPhaseAndNotify(IServiceScope scope, IMailService mail, string bidId)
        {
            YotyContext          context              = scope.ServiceProvider.GetRequiredService <YotyContext>();
            IBidsManager         bidsManager          = new BidsManager(null, context);
            NotificationsManager notificationsManager = new NotificationsManager(context, mail);

            Response <BidPhase> updatePhaseResponse;

            try
            {
                updatePhaseResponse = await bidsManager.TryUpdatePhase(bidId).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message
                });
            }

            Response notificationResponse = null;
            Response modifyDbResponse     = null;

            if (!updatePhaseResponse.IsOperationSucceeded)
            {
                Console.WriteLine($"UpdatePhase bidId:{bidId}, no update needed");
                return(new Response()
                {
                    IsOperationSucceeded = true, SuccessOrFailureMessage = updatePhaseResponse.SuccessOrFailureMessage
                });
            }
            switch (updatePhaseResponse.DTOObject)
            {
            case BidPhase.Vote:
                Console.WriteLine($"UpdatePhase bidId:{bidId}, new phase is vote");
                notificationResponse = await notificationsManager.NotifyBidTimeToVote(bidId).ConfigureAwait(false);

                modifyDbResponse = await bidsManager.UpdateBidProposalsToRelevant(bidId).ConfigureAwait(false);

                break;

            case BidPhase.Payment:
                Console.WriteLine($"UpdatePhase bidId:{bidId}, new phase is payment");
                notificationResponse = await notificationsManager.NotifyBidTimeToPay(bidId).ConfigureAwait(false);

                modifyDbResponse = await bidsManager.GetProposalWithMaxVotes(bidId).ConfigureAwait(false);

                if (modifyDbResponse.IsOperationSucceeded)
                {
                    // TODO figure better condition
                    notificationResponse = await notificationsManager.NotifyBidChosenSupplier(bidId).ConfigureAwait(false);
                }
                break;

            case BidPhase.CancelledSupplierNotFound:
                Console.WriteLine($"UpdatePhase bidId:{bidId}, new phase is canceled no relevant proposals found");
                notificationResponse = await notificationsManager.NotifyBidParticipantsSupplierNotFoundCancellation(bidId).ConfigureAwait(false);

                modifyDbResponse = await bidsManager.UpdateBidProposalsToRelevant(bidId).ConfigureAwait(false);

                break;

            case BidPhase.CancelledNotEnoughBuyersPayed:
                Console.WriteLine($"UpdatePhase bidId:{bidId}, new phase is canceled not enough consumers paid");
                modifyDbResponse = await bidsManager.CancelBid(bidId).ConfigureAwait(false);

                if (modifyDbResponse.IsOperationSucceeded)
                {
                    notificationResponse = await notificationsManager.NotifyBidAllMissingPaymentsCancellation(bidId).ConfigureAwait(false);
                }
                break;

            case BidPhase.Completed:
                Console.WriteLine($"UpdatePhase bidId:{bidId}, new phase is completed");
                modifyDbResponse = await bidsManager.CompleteBid(bidId).ConfigureAwait(false);

                if (modifyDbResponse.IsOperationSucceeded)
                {
                    notificationResponse = await notificationsManager.NotifyBidAllCompletion(bidId).ConfigureAwait(false);
                }
                break;
            }
            if (notificationResponse != null && !notificationResponse.IsOperationSucceeded)
            {
                return(notificationResponse);
            }
            if (modifyDbResponse != null && !modifyDbResponse.IsOperationSucceeded)
            {
                //TODO need to update
                return(modifyDbResponse);
            }
            return(new Response()
            {
                IsOperationSucceeded = true, SuccessOrFailureMessage = "TryUpdateBidPhaseAndNotify Success!"
            });
        }
コード例 #3
0
ファイル: BidsManager.cs プロジェクト: yotamc4/GoogleWorkShop
 public BidsManager(IMapper mapper, YotyContext context)
 {
     _mapper  = mapper;
     _context = context;
 }
コード例 #4
0
 public NotificationsManager(YotyContext context, IMailService mail)
 {
     _context = context;
     _mail    = mail;
 }
コード例 #5
0
 public AutoCompleteController(YotyContext context)
 {
     this._context = context;
 }
コード例 #6
0
 public BidOwnerPolicyHandler(YotyContext dbContext) : base()
 {
     this.dbContext = dbContext;
 }
コード例 #7
0
 public SuppliersManager(IMapper mapper, YotyContext context)
 {
     _mapper  = mapper;
     _context = context;
 }
コード例 #8
0
 public ChosenSupplierPolicyHandler(YotyContext dbContext) : base()
 {
     this.dbContext = dbContext;
 }
コード例 #9
0
 public BuyerAuthorizationHandler(YotyContext dbContext)
 {
     this.dbContext = dbContext;
 }