示例#1
0
 /// <summary>
 /// This method  will do order processing
 /// </summary>
 /// <param name="openCampaignID"></param>
 /// <param name="campaignClosingUserID"></param>
 /// <returns></returns>
 private string GenerateOrder(int openCampaignID, int campaignClosingUserID)
 {
     try
     {
         var shoppingCartInfo              = DIContainer.Resolve <IShoppingCartProvider>();
         var addrerss                      = DIContainer.Resolve <IAddressBookService>();
         var userInfo                      = DIContainer.Resolve <IKenticoUserProvider>();
         var kenticoResourceService        = DIContainer.Resolve <IKenticoResourceService>();
         var usersWithShoppingCartItems    = shoppingCartInfo.GetUserIDsWithShoppingCart(openCampaignID, Convert.ToInt32(ProductsType.PreBuy));
         var orderTemplateSettingKey       = kenticoResourceService.GetSettingsKey("KDA_OrderReservationEmailTemplate");
         var failedOrderTemplateSettingKey = kenticoResourceService.GetSettingsKey("KDA_FailedOrdersEmailTemplate");
         var failedOrdersUrl               = kenticoResourceService.GetSettingsKey("KDA_FailedOrdersPageUrl");
         var unprocessedDistributorIDs     = new List <Tuple <int, string> >();
         usersWithShoppingCartItems.ForEach(shoppingCartUser =>
         {
             var salesPerson         = userInfo.GetUserByUserId(shoppingCartUser);
             var loggedInUserCartIDs = ShoppingCartHelper.GetCartsByUserID(shoppingCartUser, ProductType.PreBuy, openCampaignID);
             loggedInUserCartIDs.ForEach(cart =>
             {
                 var shippingCost   = default(decimal);
                 Cart               = ShoppingCartInfoProvider.GetShoppingCartInfo(cart);
                 OrderDTO ordersDTO = ShoppingCartHelper.CreateOrdersDTO(Cart, Cart.ShoppingCartUserID, OrderType.prebuy, shippingCost);
                 var response       = ShoppingCartHelper.ProcessOrder(Cart, Cart.ShoppingCartUserID, OrderType.prebuy, ordersDTO, shippingCost);
                 if (response != null && response.Success)
                 {
                     ordersDTO.OrderID = response.Payload;
                     ProductEmailNotifications.SendMail(salesPerson, ordersDTO, orderTemplateSettingKey);
                     InBoundFormHelper.InsertIBFForm(ordersDTO);
                     ShoppingCartInfoProvider.DeleteShoppingCartInfo(Cart);
                     ShoppingCartHelper.UpdateRemainingBudget(ordersDTO, salesPerson.UserId);
                     DIContainer.Resolve <IIBTFService>().InsertIBTFAdjustmentRecord(ordersDTO);
                 }
                 else
                 {
                     unprocessedDistributorIDs.Add(new Tuple <int, string>(Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)), response.ErrorMessages));
                 }
             });
         });
         var distributors = addrerss.GetAddressesByAddressIds(unprocessedDistributorIDs.Select(x => x.Item1).ToList()).Select(x =>
         {
             return(new { AddressID = x?.Id, AddressPersonalName = x?.AddressPersonalName });
         }).ToList();
         var listofFailedOrders = unprocessedDistributorIDs.Select(x =>
         {
             var distributor = distributors.Where(y => y.AddressID == x.Item1).FirstOrDefault();
             return(new
             {
                 Name = distributor.AddressPersonalName,
                 Reason = x.Item2
             });
         }).ToList();
         var user = userInfo.GetUserByUserId(campaignClosingUserID);
         if (user?.Email != null && listofFailedOrders.Count > 0)
         {
             Dictionary <string, object> failedOrderData = new Dictionary <string, object>();
             failedOrderData.Add("failedorderurl", URLHelper.AddHTTPToUrl($"{SiteContext.CurrentSite.DomainName}{failedOrdersUrl}?campid={openCampaignID}"));
             failedOrderData.Add("failedordercount", listofFailedOrders.Count);
             failedOrderData.Add("failedorders", listofFailedOrders);
             ProductEmailNotifications.SendEmailNotification(failedOrderTemplateSettingKey, user.Email, listofFailedOrders, "failedOrders", failedOrderData);
             UpdatetFailedOrders(openCampaignID, true);
         }
         return(ResHelper.GetString("KDA.OrderSchedular.TaskSuccessfulMessage"));
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("GeneratePrebuyOrderTask", "GenerateOrder", ex, SiteContext.CurrentSiteID, ex.Message);
         return(ex.Message);
     }
 }