예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var ctx = ApplicationContext.Current.Campaigns;
                List<CAMPAIGN> campaigns = ctx.GetActiveCampaigns(true).OrderByDescending(c => c.StartDate).ToList();
                rptActualCampaigns.CampaignRepeater.DataSource = campaigns;
                rptActualCampaigns.CampaignRepeater.DataBind();

                CAMPAIGN campaign = new CAMPAIGN() { SearchStartDate = DateTime.Now, SearchEndDate = DateTime.Now.AddDays(Configuration.FutureCampaignDays), Approved = true };
                int totalRecords;
                List<CAMPAIGN> futureCampaigns = ctx.Search(campaign, 10, 0, out totalRecords, "StartDate", BL.Util.SortDirection.Ascending);
                if (futureCampaigns.Count > 0)
                {
                    rptFutureCampaigns.CampaignRepeater.DataSource = futureCampaigns;
                    rptFutureCampaigns.CampaignRepeater.DataBind();
                }
                else
                {
                    divFutureDeals.Visible = false;
                }
                base.Page_Load(sender, e);
            }
            catch (Exception ex)
            {
                //TODO complete exception handling
                Log(ex, ex.Message, ex.StackTrace, "Home");
            }
        }
예제 #2
0
        public void Execute()
        {
            // Retrieve users in a paginated way, to avoid loading thousands in memory
            int TotalRecords;
            List<EMAIL> customers = ApplicationContext.Current.Customers.MailList(PageSize, 0, out TotalRecords, "ID", BL.Util.SortDirection.Ascending);
            int numPages = (int)Math.Floor((double)(TotalRecords / PageSize));

            //retrieve campaigns that starts today
            int TotalCampaignsForToday;
            int TotalCampaignsForFuture;
            CAMPAIGN searchCampaign = new CAMPAIGN() { Active = true, Approved = true };
            List<CAMPAIGN> campaigns = ApplicationContext.Current.Campaigns.Search(searchCampaign, 100, 0, out TotalCampaignsForToday, "StartDate", BL.Util.SortDirection.Descending);

            searchCampaign = new CAMPAIGN() { SearchStartDate = DateTime.Today.AddDays(1), SearchEndDate = DateTime.Today.AddDays(Configuration.FutureCampaignDays), Approved = true };
            List<CAMPAIGN> campaignsFuture = ApplicationContext.Current.Campaigns.Search(searchCampaign, 100, 0, out TotalCampaignsForFuture, "StartDate", BL.Util.SortDirection.Ascending);

            CAMPAIGN todaySearchCampaign = new CAMPAIGN() { SearchStartDate = DateTime.Today, SearchEndDate = DateTime.Today.AddHours(23) };
            List<CAMPAIGN> todayCampaigns = ApplicationContext.Current.Campaigns.Search(todaySearchCampaign, 100, 0, out TotalCampaignsForToday, "Name", BL.Util.SortDirection.Ascending);

            if (todayCampaigns == null || todayCampaigns.Count == 0)
            {
                log("There are no campaigns starting today!");
                return;
            }

            StringBuilder subject = new StringBuilder();
            subject.Append("Sot ne FZone: ");
            for (int i = 0; i < campaigns.Count; i++)
            {
                if (i != 0 && campaigns.Count > 1 && i == (campaigns.Count - 1))
                {
                    subject.Append(" dhe ");
                }

                if (i != 0 && campaigns.Count != 1 && i != (campaigns.Count - 1))
                {
                    subject.Append(", ");
                }

                subject.Append(campaigns.ElementAt(i).BrandName);
            }        
            
            for (int i = 0; i <= numPages; i++)
            {
                if (i != 0)
                {
                    customers = ApplicationContext.Current.Customers.MailList(PageSize, i, out TotalRecords, "ID", BL.Util.SortDirection.Ascending);
                }
                foreach (EMAIL email in customers)
                {
                    SendEmail(email, campaigns, subject.ToString(), campaignsFuture);
                    // TODO decide if this should be done in different threads/tasks
                }
            }
            log("Newsletter sending terminated");
        }
예제 #3
0
        public List<CAMPAIGN> Search(CAMPAIGN Campaign, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, SortDirection SortDirection)
        {
            var result = Context.CAMPAIGN.Include("BRAND").AsQueryable();

            if (Campaign != null)
            {
                if (!String.IsNullOrWhiteSpace(Campaign.Name))
                {
                    result = result.Where(c => c.Name.Contains(Campaign.Name));
                }

                if (!String.IsNullOrWhiteSpace(Campaign.BrandName))
                {
                    result = result.Where(c => c.BRAND.Name.Contains(Campaign.Name));
                }

                if (Campaign.SearchStartDate.HasValue)
                {
                    result = result.Where(c => c.StartDate >= Campaign.SearchStartDate.Value);
                }

                if (Campaign.SearchEndDate.HasValue)
                {
                    result = result.Where(c => c.StartDate <= Campaign.SearchEndDate.Value);
                }

                if (Campaign.Active)
                {
                    result = result.Where(c => c.Active);
                }
                if (Campaign.Approved.HasValue)
                {
                    result = result.Where(c => c.Approved == Campaign.Approved.Value);
                }
            }

            TotalRecords = result.Count();

            if (!String.IsNullOrEmpty(OrderExp) && OrderExp.Equals("BrandName"))
            {
                if (SortDirection == SortDirection.Ascending)
                    result = result.OrderBy(c => c.BRAND.ShowName);
                else
                    result = result.OrderByDescending(c => c.BRAND.ShowName);
            }
            else
            {
                var sorter = new GenericSorterCaller<CAMPAIGN>();
                result = sorter.Sort(result, String.IsNullOrEmpty(OrderExp) ? "ID" : OrderExp, SortDirection);
            }
            // pagination
            return result.Skip(PageIndex * PageSize).Take(PageSize).ToList();
        }
예제 #4
0
        private void FixupCAMPAIGN(CAMPAIGN previousValue)
        {
            if (previousValue != null && previousValue.ORDER_DETAIL.Contains(this))
            {
                previousValue.ORDER_DETAIL.Remove(this);
            }

            if (CAMPAIGN != null)
            {
                if (!CAMPAIGN.ORDER_DETAIL.Contains(this))
                {
                    CAMPAIGN.ORDER_DETAIL.Add(this);
                }
                if (CampaignID != CAMPAIGN.ID)
                {
                    CampaignID = CAMPAIGN.ID;
                }
            }
        }
예제 #5
0
        private void FixupCAMPAIGN(CAMPAIGN previousValue)
        {
            if (previousValue != null && previousValue.SHOPPING_CART.Contains(this))
            {
                previousValue.SHOPPING_CART.Remove(this);
            }

            if (CAMPAIGN != null)
            {
                if (!CAMPAIGN.SHOPPING_CART.Contains(this))
                {
                    CAMPAIGN.SHOPPING_CART.Add(this);
                }
                if (CampaignID != CAMPAIGN.ID)
                {
                    CampaignID = CAMPAIGN.ID;
                }
            }
        }
예제 #6
0
        private void FixupCAMPAIGN(CAMPAIGN previousValue)
        {
            if (previousValue != null && previousValue.CATEGORY.Contains(this))
            {
                previousValue.CATEGORY.Remove(this);
            }

            if (CAMPAIGN != null)
            {
                if (!CAMPAIGN.CATEGORY.Contains(this))
                {
                    CAMPAIGN.CATEGORY.Add(this);
                }
                if (CampaignID != CAMPAIGN.ID)
                {
                    CampaignID = CAMPAIGN.ID;
                }
            }
            else if (!_settingFK)
            {
                CampaignID = null;
            }
        }
예제 #7
0
 public void ChangeApproval(CAMPAIGN Campaign)
 {
     Context.CAMPAIGN.Attach(Campaign);
     var entry = Context.ObjectStateManager.GetObjectStateEntry(Campaign);
     entry.SetModifiedProperty("Approved");
     entry.SetModifiedProperty("ApprovedBy");
 }
예제 #8
0
 public void DeleteById(int id)
 {
     CAMPAIGN obj = new CAMPAIGN() { ID = id };
     Delete(obj);
 }
예제 #9
0
 /// <summary>
 /// Delete CAMPAIGN elment.
 /// </summary>
 /// <param name="delCampaign">The CAMPAIGN object that will delete.</param>
 public void Delete(CAMPAIGN delCampaign)
 {
     Context.CAMPAIGN.Attach(delCampaign);
     Context.DeleteObject(delCampaign);
     //Context.SaveChanges();
 }
예제 #10
0
 /// <summary>
 /// Update CAMPAIGN elment.
 /// </summary>
 /// <param name="upCampaign">The CAMPAIGN object that will update.</param>
 public void Update(CAMPAIGN upCampaign, bool Attach)
 {
     if (Attach)
     {
         Context.CAMPAIGN.Attach(upCampaign);
     }
     var entry = Context.ObjectStateManager.GetObjectStateEntry(upCampaign);
     entry.SetModifiedProperty("Name");
     entry.SetModifiedProperty("Description");
     entry.SetModifiedProperty("StartDate");
     entry.SetModifiedProperty("EndDate");
     entry.SetModifiedProperty("DeliveryStartDate");
     entry.SetModifiedProperty("DeliveryEndDate");
     entry.SetModifiedProperty("Logo");
     entry.SetModifiedProperty("ImageHome");
     entry.SetModifiedProperty("ImageDetail");
     entry.SetModifiedProperty("ImageListHeader");
     entry.SetModifiedProperty("GenericFile");
 }
예제 #11
0
 public void Delete(CAMPAIGN Campaign)
 {
     _campaignDAO.Delete(Campaign);
     Context.SaveChanges();
 }
예제 #12
0
 public void Update(CAMPAIGN Campaign, bool Attach = true)
 {
     _campaignDAO.Update(Campaign, Attach);
     Context.SaveChanges();
 }
예제 #13
0
 public void Insert(CAMPAIGN Campaign)
 {
     _campaignDAO.Insert(Campaign);
     Context.SaveChanges();
 }
예제 #14
0
 public List<CAMPAIGN> Search(CAMPAIGN Campaign, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection)
 {
     return _campaignDAO.Search(Campaign, PageSize, PageIndex, out TotalRecords, OrderExp, SortDirection);
 }
예제 #15
0
        private void setCampaignImg(PRODUCT product, CAMPAIGN campaign)
        {
            if (product.CampaignID.HasValue)
            {
                int campaignId = product.CampaignID.Value;
                if (campaign != null)
                {
                    CampaignID = campaign.ID;
                    imgBrandLogo.ImageUrl = Configuration.ImagesUploadPath + campaign.Logo;
                    imgBrandLogo.AlternateText = campaign.Name;

                    if (campaign.BRAND != null && campaign.BRAND.Shop.HasValue && campaign.BRAND.Shop.Value)
                    {
                        lblEstimatedDelivery.Text = Resources.Lang.ProductPickUpLabel + "<br />";
                        litEstimatedDates.Text = campaign.BRAND.Address;
                        lblInfo.Visible = true;
                        lblInfo.Text = "<br />" + Resources.Lang.ProductExclusivityLabel;
                    }
                    else
                    {
                        litEstimatedDates.Text = campaign.DeliveryStartDate.Value.ToString("dd/MM/yyyy") + " - " +
                            campaign.DeliveryEndDate.Value.ToString("dd/MM/yyyy");
                    }
                }
            }
        }
예제 #16
0
 public void Update(CAMPAIGN Entity)
 {
     Update(Entity, true);
 }
예제 #17
0
 public void ChangeApproval(CAMPAIGN Campaign)
 {
     _campaignDAO.ChangeApproval(Campaign);
 }
예제 #18
0
     private void FixupCAMPAIGN(CAMPAIGN previousValue)
     {
         if (previousValue != null && previousValue.ORDER_DETAIL.Contains(this))
         {
             previousValue.ORDER_DETAIL.Remove(this);
         }
 
         if (CAMPAIGN != null)
         {
             if (!CAMPAIGN.ORDER_DETAIL.Contains(this))
             {
                 CAMPAIGN.ORDER_DETAIL.Add(this);
             }
             if (CampaignID != CAMPAIGN.ID)
             {
                 CampaignID = CAMPAIGN.ID;
             }
         }
     }
예제 #19
0
        public static string GenerateBonusMail(CUSTOMER Customer)
        {
            // Input data will be defined in this XML document.
            XmlDocument xmlDoc = new XmlDocument();

            XmlElement xmlRoot;
            XmlNode xmlNode, xmlChild2, xmlChild, xmlNode3;

            xmlDoc.LoadXml(
            "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
            "<Root>" +
            "<Customer/>" +
            "<Invited/>" +
            "<Bonus/>" +
            "<Url/>" +
            "<Campaigns/>" +
            "</Root>");

            // Set the values of the XML nodes that will be used by XSLT.
            xmlRoot = xmlDoc.DocumentElement;

            xmlNode = xmlRoot.SelectSingleNode("/Root/Customer");

            xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "Name", null);
            xmlChild2.InnerText = Customer.CUSTOMER2.Name + " " + Customer.CUSTOMER2.Surname;
            xmlNode.AppendChild(xmlChild2);

            xmlNode = xmlRoot.SelectSingleNode("/Root/Url");
            xmlNode.InnerText = Configuration.DeploymentURL;

            xmlNode = xmlRoot.SelectSingleNode("/Root/Invited");
            xmlNode.InnerText = Customer.Email;

            xmlNode = xmlRoot.SelectSingleNode("/Root/Bonus");
            xmlNode.InnerText = Configuration.BonusValue.ToString() + " €";

            xmlNode3 = xmlRoot.SelectSingleNode("/Root/Campaigns");

            CAMPAIGN searchCampaign = new CAMPAIGN() { Active = true, Approved = true };
            int TotalCampaignsForToday;
            List<CAMPAIGN> campaigns = ApplicationContext.Current.Campaigns.Search(searchCampaign, 100, 0, out TotalCampaignsForToday, "StartDate", BL.Util.SortDirection.Descending);

            string path;
            foreach (CAMPAIGN campaign in campaigns)
            {
                xmlChild = xmlDoc.CreateNode(XmlNodeType.Element, "Campaign", null);

                // title
                xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "Title", null);
                xmlChild2.InnerText = campaign.BrandName;
                xmlChild.AppendChild(xmlChild2);

                // from
                //xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "From", null);
                //xmlChild2.InnerText = campaign.StartDate.ToString("dd/MM/yyyy");
                //xmlChild.AppendChild(xmlChild2);

                // to
                xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "To", null);
                xmlChild2.InnerText = campaign.EndDate.ToString("dd/MM/yyyy");
                xmlChild.AppendChild(xmlChild2);

                // image
                xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "Image", null);
                if (Configuration.ImagesVisualizationPath.Contains(Configuration.DeploymentURL))
                    path = Configuration.ImagesVisualizationPath;
                else
                    path = Configuration.DeploymentURL + Configuration.ImagesVisualizationPath;
                xmlChild2.InnerText = path + campaign.ImageHome;
                xmlChild.AppendChild(xmlChild2);

                // Url
                xmlChild2 = xmlDoc.CreateNode(XmlNodeType.Element, "Url", null);
                xmlChild2.InnerText = Configuration.DeploymentURL + "/campaign/" + Encryption.Encrypt(campaign.ID.ToString());
                xmlChild.AppendChild(xmlChild2);

                xmlNode3.AppendChild(xmlChild);
            }

            // This is our XSL template.
            XslCompiledTransform xslDoc = new XslCompiledTransform();
            xslDoc.Load(@Configuration.BonusTemplate);

            XsltArgumentList xslArgs = new XsltArgumentList();
            StringWriter writer = new StringWriter();

            // Merge XSLT document with data XML document 
            // (writer will hold resulted transformation).
            xslDoc.Transform(xmlDoc, xslArgs, writer);

            return writer.ToString();
        }
예제 #20
0
 /// <summary>
 /// Insert new CAMPAIGN element.
 /// </summary>
 /// <param name="newCampaign">CAMPAIGN object.</param>
 public void Insert(CAMPAIGN newCampaign)
 {
     Context.CAMPAIGN.AddObject(newCampaign);
     //Context.SaveChanges();
 }
예제 #21
0
     private void FixupCAMPAIGN(CAMPAIGN previousValue)
     {
         if (previousValue != null && previousValue.CATEGORY.Contains(this))
         {
             previousValue.CATEGORY.Remove(this);
         }
 
         if (CAMPAIGN != null)
         {
             if (!CAMPAIGN.CATEGORY.Contains(this))
             {
                 CAMPAIGN.CATEGORY.Add(this);
             }
             if (CampaignID != CAMPAIGN.ID)
             {
                 CampaignID = CAMPAIGN.ID;
             }
         }
         else if (!_settingFK)
         {
             CampaignID = null;
         }
     }
예제 #22
0
        private void FixupCAMPAIGN(CAMPAIGN previousValue)
        {
            if (previousValue != null && previousValue.SHOPPING_CART.Contains(this))
            {
                previousValue.SHOPPING_CART.Remove(this);
            }

            if (CAMPAIGN != null)
            {
                if (!CAMPAIGN.SHOPPING_CART.Contains(this))
                {
                    CAMPAIGN.SHOPPING_CART.Add(this);
                }
                if (CampaignID != CAMPAIGN.ID)
                {
                    CampaignID = CAMPAIGN.ID;
                }
            }
        }