/// <summary>
    /// Open the Campaign
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lnkOpenCampaign_Click(object sender, EventArgs e)
    {
        try
        {
            LinkButton btn        = (LinkButton)sender;
            int        campaignID = ValidationHelper.GetInteger(btn.CommandArgument, 0);
            Campaign   campaign   = CampaignProvider.GetCampaigns()
                                    .WhereEquals("NodeSiteID", CurrentSite.SiteID)
                                    .WhereEquals("CampaignID", campaignID)
                                    .FirstObject;
            if (campaign != null)
            {
                campaign.OpenCampaign = true;
                campaign.Update();

                var users = UserInfoProvider.GetUsers();
                if (users != null)
                {
                    foreach (var user in users)
                    {
                        ProductEmailNotifications.CampaignEmail(campaign.DocumentName, user.Email, "CampaignOpenEmail");
                    }
                }
                Response.Redirect(CurrentDocument.DocumentUrlPath);
            }
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("CMSWebParts_Kadena_Campaign_Web_Form_CampaignWebFormActions", "lnkOpenCampaign_Click", ex, CurrentSite.SiteID, ex.Message);
        }
    }
Esempio n. 2
0
 /// <summary>
 /// Closing the campaign
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public static void ProcessOrders(int campaignID)
 {
     try
     {
         Campaign campaign = CampaignProvider.GetCampaigns()
                             .WhereEquals("NodeSiteID", SiteContext.CurrentSiteID)
                             .WhereEquals("CampaignID", campaignID)
                             .FirstObject;
         if (campaign != null)
         {
             var _failedOrders = DIContainer.Resolve <IFailedOrderStatusProvider>();
             _failedOrders.UpdateCampaignOrderStatus(campaign.CampaignID);
             TaskInfo runTask = TaskInfoProvider.GetTaskInfo(ScheduledTaskNames.PrebuyOrderCreation, SiteContext.CurrentSiteID);
             if (runTask != null)
             {
                 runTask.TaskRunInSeparateThread = true;
                 runTask.TaskEnabled             = true;
                 runTask.TaskData = $"{campaign.CampaignID}|{SiteContext.CurrentSiteID}";
                 SchedulingExecutor.ExecuteTask(runTask);
             }
             var users = UserInfoProvider.GetUsers();
             if (users != null)
             {
                 foreach (var user in users)
                 {
                     ProductEmailNotifications.CampaignEmail(campaign.DocumentName, user.Email, "CampaignCloseEmail");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("Kadena_CMSWebParts_Kadena_Cart_FailedOrdersCheckout", "ProcessOrders", ex, SiteContext.CurrentSiteID, ex.Message);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Nottify Admin
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnNotifyAdmin_Click(object sender, EventArgs e)
 {
     try
     {
         var      nodeGuid      = CurrentDocument.NodeGUID;
         var      emailTemplate = DIContainer.Resolve <IKenticoResourceService>().GetSettingsKey(SiteContext.CurrentSiteID, "KDA_CampaignProductAddedTemplate");
         Campaign campaign      = CampaignProvider.GetCampaign(nodeGuid, CurrentDocument.DocumentCulture, CurrentSite.SiteName);
         var      program       = ProgramProvider.GetPrograms()
                                  .WhereEquals("ProgramId", ddlPrograms.SelectedValue)
                                  .FirstOrDefault();
         if (program != null)
         {
             program.GlobalAdminNotified = true;
             program.Update();
             var roleName = SettingsKeyInfoProvider.GetValue(CurrentSite.SiteName + ".KDA_GlobalAminRoleName");
             var role     = RoleInfoProvider.GetRoleInfo(roleName, CurrentSite.SiteID);
             if (role != null)
             {
                 var users = RoleInfoProvider.GetRoleUsers(role.RoleID);
                 if (users != null)
                 {
                     foreach (var user in users.AsEnumerable().ToList())
                     {
                         ProductEmailNotifications.CampaignEmail(campaign.DocumentName, user.Field <string>("Email"), emailTemplate, program.DocumentName);
                     }
                 }
             }
             Response.Redirect(CurrentDocument.DocumentUrlPath, false);
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("CMSWebParts_Kadena_Campaign_Web_Form_CampaignProductsFilter", "btnNotifyAdmin_Click", ex, CurrentSite.SiteID, ex.Message);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// displays the unprocessed order distributors names
        /// </summary>
        /// <param name="addresses"></param>
        private void ShowOrderErrorList(List <Tuple <int, string> > unprocessedDistributorIDs)
        {
            try
            {
                var addrerss     = DIContainer.Resolve <IAddressBookService>();
                var distributors = addrerss.GetAddressesByAddressIds(unprocessedDistributorIDs.Select(x => x.Item1).ToList()).Select(x =>
                {
                    return(new { AddressID = x?.Id, AddressPersonalName = x?.AddressPersonalName });
                }).ToList();
                var unprocessedOrders = unprocessedDistributorIDs.Select(x =>
                {
                    var distributor = distributors.Where(y => y.AddressID == x.Item1).FirstOrDefault();
                    return(new
                    {
                        AddressPersonalName = distributor.AddressPersonalName,
                        Reason = x.Item2
                    });
                }).ToList();
                var userInfo = DIContainer.Resolve <IKenticoUserProvider>().GetUserByUserId(CurrentUser.UserID);
                if (userInfo?.Email != null)
                {
                    Dictionary <string, object> orderDetails = new Dictionary <string, object>();
                    orderDetails.Add("name", userInfo.FirstName);
                    orderDetails.Add("failedordercount", unprocessedOrders.Count);
                    ProductEmailNotifications.SendEmailNotification(settingKeys.GetSettingsKey("KDA_FailedOrdersEmailTemplateGI"), CurrentUser?.Email, unprocessedOrders, "failedOrders", orderDetails);
                }

                rptErrors.DataSource = unprocessedOrders;
                rptErrors.DataBind();
            }
            catch (Exception ex)
            {
                EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_CartCheckout", "ShowError", ex.Message);
            }
        }
Esempio n. 5
0
        public void ShouldSentProductAlert()
        {
            ProductEmailNotifications productEmailNotifications = new ProductEmailNotifications(crudOnAlerts, mailSender);
            var product = TestInitialiser.CreateProduct();

            product.Title = "ceva bun tare";
            var addedProduct = crudOnProducts.AddOrUpdate(product).Result;

            productEmailNotifications.SendEmailForProduct("ceva", addedProduct.Id);
            Assert.True(true);

            crudOnProducts.DeleteProduct(addedProduct.Id).Wait();
        }
 /// <summary>
 /// Closing the campaign
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void lnkCloseCampaign_Click(object sender, EventArgs e)
 {
     try
     {
         LinkButton btn        = (LinkButton)sender;
         int        campaignID = ValidationHelper.GetInteger(btn.CommandArgument, 0);
         if (!DIContainer.Resolve <IShoppingCartProvider>().ValidateAllCarts(campaignID: campaignID))
         {
             Response.Cookies["status"].Value    = QueryStringStatus.InvalidCartItems;
             Response.Cookies["status"].HttpOnly = false;
             return;
         }
         Campaign campaign = CampaignProvider.GetCampaigns()
                             .WhereEquals("NodeSiteID", CurrentSite.SiteID)
                             .WhereEquals("CampaignID", campaignID)
                             .FirstObject;
         if (campaign != null)
         {
             campaign.CloseCampaign = true;
             campaign.Update();
             var oderStatus = DIContainer.Resolve <IFailedOrderStatusProvider>();
             oderStatus.InsertCampaignOrdersInProgress(campaign.CampaignID);
             TaskInfo runTask = TaskInfoProvider.GetTaskInfo(ScheduledTaskNames.PrebuyOrderCreation, CurrentSite.SiteID);
             if (runTask != null)
             {
                 runTask.TaskRunInSeparateThread = true;
                 runTask.TaskEnabled             = true;
                 runTask.TaskData = $"{campaign.CampaignID}|{CurrentUser.UserID}";
                 SchedulingExecutor.ExecuteTask(runTask);
             }
             var users = UserInfoProvider.GetUsers();
             if (users != null)
             {
                 foreach (var user in users)
                 {
                     ProductEmailNotifications.CampaignEmail(campaign.DocumentName, user.Email, "CampaignCloseEmail");
                 }
             }
             Response.Redirect(CurrentDocument.DocumentUrlPath);
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("CMSWebParts_Kadena_Campaign_Web_Form_CampaignWebFormActions", "lnkCloseCampaign_Click", ex, CurrentSite.SiteID, ex.Message);
     }
 }
 /// <summary>
 /// Pop up Yes click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void popUpYes_ServerClick(object sender, EventArgs e)
 {
     try
     {
         int  campaignID = ValidationHelper.GetInteger(ddlCampaign.SelectedValue, default(int));
         var  client     = DIContainer.Resolve <IKenticoCampaignsProvider>();
         bool result     = client.CloseCampaignIBTF(campaignID);
         var  emailNotificationTemplate = DIContainer.Resolve <IKenticoResourceService>().GetSettingsKey(SiteContext.CurrentSiteID, "KDA_IBTFFinalizeEmailTemplate");
         if (result)
         {
             DIContainer.Resolve <IIBTFService>().UpdateRemainingBudget(campaignID);
             ProductEmailNotifications.GetCampaignOrders(campaignID, emailNotificationTemplate);
             btnClose.Enabled = false;
             GetProducts();
             Response.Cookies["status"].Value    = QueryStringStatus.Updated;
             Response.Cookies["status"].HttpOnly = false;
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("CloseButtonYesClick", "popUpYes_ServerClick()", ex, CurrentSite.SiteID, ex.Message);
     }
 }
Esempio n. 8
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);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Chekcou click event for order processing
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void lnkCheckout_Click(object sender, EventArgs e)
 {
     try
     {
         if (!DIContainer.Resolve <IShoppingCartProvider>().ValidateAllCarts(userID: CurrentUser.UserID))
         {
             Response.Cookies["status"].Value    = QueryStringStatus.InvalidCartItems;
             Response.Cookies["status"].HttpOnly = false;
             return;
         }
         var loggedInUserCartIDs       = GetCartsByUserID(CurrentUser.UserID, ProductType.GeneralInventory, OpenCampaign?.CampaignID); settingKeys = DIContainer.Resolve <IKenticoResourceService>();
         var orderTemplateSettingKey   = settingKeys.GetSettingsKey("KDA_OrderReservationEmailTemplateGI");
         var unprocessedDistributorIDs = new List <Tuple <int, string> >();
         var userInfo    = DIContainer.Resolve <IKenticoUserProvider>();
         var salesPerson = userInfo.GetUserByUserId(CurrentUser.UserID);
         loggedInUserCartIDs.ForEach(distributorCart =>
         {
             Cart = ShoppingCartInfoProvider.GetShoppingCartInfo(distributorCart);
             decimal shippingCost = default(decimal);
             if (Cart.ShippingOption != null && Cart.ShippingOption.ShippingOptionName.ToLower() != ShippingOption.Ground)
             {
                 var shippingResponse = GetOrderShippingTotal(Cart);
                 if (shippingResponse != null && shippingResponse.Success)
                 {
                     shippingCost = ValidationHelper.GetDecimal(shippingResponse?.Payload?.Cost, default(decimal));
                 }
                 else
                 {
                     unprocessedDistributorIDs.Add(new Tuple <int, string>(Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)), shippingResponse.ErrorMessages));
                     return;
                 }
             }
             OrderDTO ordersDTO = CreateOrdersDTO(Cart, Cart.ShoppingCartUserID, OrderType.generalInventory, shippingCost);
             var response       = ProcessOrder(Cart, CurrentUser.UserID, OrderType.generalInventory, ordersDTO, shippingCost);
             if (response != null && response.Success)
             {
                 UpdateAvailableSKUQuantity(Cart);
                 UpdateAllocatedProductQuantity(Cart, salesPerson.UserId);
                 ProductEmailNotifications.SendMail(salesPerson, ordersDTO, orderTemplateSettingKey);
                 ShoppingCartInfoProvider.DeleteShoppingCartInfo(Cart);
                 ShoppingCartHelper.UpdateRemainingBudget(ordersDTO, CurrentUser.UserID);
             }
             else
             {
                 unprocessedDistributorIDs.Add(new Tuple <int, string>(Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)), response.ErrorMessages));
             }
         });
         if (unprocessedDistributorIDs.Count == 0)
         {
             Response.Cookies["status"].Value    = QueryStringStatus.OrderSuccess;
             Response.Cookies["status"].HttpOnly = false;
             URLHelper.Redirect(Request.RawUrl);
         }
         else
         {
             if (loggedInUserCartIDs.Count > unprocessedDistributorIDs.Count)
             {
                 Response.Cookies["status"].Value    = QueryStringStatus.OrderSuccess;
                 Response.Cookies["status"].HttpOnly = false;
             }
             Response.Cookies["error"].Value    = QueryStringStatus.OrderFail;
             Response.Cookies["error"].HttpOnly = false;
             ShowOrderErrorList(unprocessedDistributorIDs);
             divErrorDailogue.Attributes.Add("class", "dialog active");
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogInformation("Kadena_CMSWebParts_Kadena_Cart_CartCheckout", "lnkCheckout_Click", ex.Message);
     }
 }