internal void tearDown()
 {
     try
     {
         dataUsers.RemoveRange(dataUsers.ToList());
         adminUsers.RemoveRange(adminUsers.ToList());
         states.RemoveRange(states.ToList());
         statistics.RemoveRange(statistics.ToList());
         productInCarts.RemoveRange(productInCarts.ToList());
         membersShoppingBaskets.RemoveRange(membersShoppingBaskets.ToList());
         membersShoppingCarts.RemoveRange(membersShoppingCarts.ToList());
         appointers.RemoveRange(appointers.ToList());
         Prem.RemoveRange(Prem.ToList());
         managers.RemoveRange(managers.ToList());
         products.RemoveRange(products.ToList());
         addresses.RemoveRange(addresses.ToList());
         BidsManager.RemoveRange(BidsManager.ToList());
         transactionStatuses.RemoveRange(transactionStatuses.ToList());
         deliveryStatuses.RemoveRange(deliveryStatuses.ToList());
         purchasedProducts.RemoveRange(purchasedProducts.ToList());
         productHistoryDatas.RemoveRange(productHistoryDatas.ToList());
         paymentStatuses.RemoveRange(paymentStatuses.ToList());
         stores.RemoveRange(stores.ToList());
         PurchasePolicy.RemoveRange(PurchasePolicy.ToList());
         categories.RemoveRange(categories.ToList());
         marketRulesRequestType1.RemoveRange(marketRulesRequestType1.ToList());
         marketRulesRequestType2.RemoveRange(marketRulesRequestType2.ToList());
         marketRulesRequestType3.RemoveRange(marketRulesRequestType3.ToList());
         marketRulesRequestType4.RemoveRange(marketRulesRequestType4.ToList());
         marketRulesRequestType5.RemoveRange(marketRulesRequestType5.ToList());
         marketRulesRequestType6.RemoveRange(marketRulesRequestType6.ToList());
         marketRulesRequestType7.RemoveRange(marketRulesRequestType7.ToList());
         marketRulesRequestType8.RemoveRange(marketRulesRequestType8.ToList());
         SaveChanges();
     }
     catch (Exception e)
     {
     }
 }
Ejemplo n.º 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!"
            });
        }