public bool RegisterCampaign(CAMPAIGN campaign, List <CAMPAIGN_SETTINGS> listCampaignSettings, FileUpload fileUpload) { try { campaign.IdCampaign = Guid.NewGuid(); campaign.RegisterDate = DateTime.Now; PRODUCT p = (from r in _context.PRODUCTS where r.IdProduct.Equals(campaign.PRODUCT.IdProduct) select r).FirstOrDefault(); AspNetUser u = (from r in _context.AspNetUsers where r.Email.Equals(campaign.AspNetUser.Email) select r).FirstOrDefault(); campaign.PRODUCT = p; campaign.AspNetUser = u; campaign.CAT_CAMPAIGN_STATUS_IdStatus = (int)CatCampaignStatusEnum.In_Review; _context.Set <CAMPAIGN>().Add(campaign); if (listCampaignSettings != null && listCampaignSettings.Any()) { foreach (var setting in listCampaignSettings) { setting.IdCampaignSetting = Guid.NewGuid(); setting.CAMPAIGNs1 = campaign; setting.CAMPAIGNs1_IdCampaign = campaign.IdCampaign; if (setting.SettingName.Equals("pushNotifImage")) { setting.SettingValue = GetImageAzure(fileUpload); } _context.Set <CAMPAIGN_SETTINGS>().Add(setting); } } } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } return(_context.SaveChanges() > 0); }
public void CopyCampaign(int CampaignId, string NewName) { CAMPAIGN camp = Context.CAMPAIGN.Where(c => c.ID == CampaignId).FirstOrDefault(); Context.Detach(camp); camp.ID = 0; }
public bool ModifyCampaign(CAMPAIGN campaign, ICollection <CAMPAIGN_SETTINGS> listCampaignSettings, FileUpload fileUpload) { _context.Entry(campaign).State = EntityState.Modified; try { if (listCampaignSettings != null && listCampaignSettings.Any()) { foreach (var setting in listCampaignSettings) { if (setting.SettingName.Equals("pushNotifImage")) { if (fileUpload != null && fileUpload.FileData != null && fileUpload.Filextension != null) { setting.SettingValue = GetImageAzure(fileUpload); } } _context.Entry(setting).State = EntityState.Modified; } } } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } return(_context.SaveChanges() > 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"); } }
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"); } } } }
public void ChangeApproval(CAMPAIGN Campaign) { Context.CAMPAIGN.Attach(Campaign); var entry = Context.ObjectStateManager.GetObjectStateEntry(Campaign); entry.SetModifiedProperty("Approved"); entry.SetModifiedProperty("ApprovedBy"); }
public void DeleteById(int id) { CAMPAIGN obj = new CAMPAIGN() { ID = id }; Delete(obj); }
private CAMPAIGN GetCampaign(int id) { CAMPAIGN campaign = null; try { campaign = ApplicationContext.Current.Campaigns.GetById(id); if (campaign != null) { txtEncryptedId.Text = FashionZone.BL.Util.Encryption.Encrypt(id.ToString()); txtName.Text = campaign.Name; txtBrand.Text = campaign.BrandName; txtDesc.Text = campaign.Description; txtDateFrom.Text = campaign.StartDate.Date.ToString("dd/MM/yyyy"); txtTimeFrom.Text = campaign.StartDate.ToString("HH:mm"); txtDateTo.Text = campaign.EndDate.Date.ToString("dd/MM/yyyy"); txtTimeTo.Text = campaign.EndDate.ToString("HH:mm"); if (campaign.Approved.HasValue) { chkApproved.Checked = campaign.Approved.Value; if (campaign.USER != null) { txtApprover.Text = campaign.USER.Login; } } if (campaign.DeliveryStartDate.HasValue) { txtDeliveryStart.Text = campaign.DeliveryStartDate.Value.Date.ToString("dd/MM/yyyy"); } if (campaign.DeliveryEndDate.HasValue) { txtDeliveryEnd.Text = campaign.DeliveryEndDate.Value.Date.ToString("dd/MM/yyyy"); } // Uploads uplHome.FileName = campaign.ImageHome; uplLogo.FileName = campaign.Logo; uplImgDet.FileName = campaign.ImageDetail; uplImgHeader.FileName = campaign.ImageListHeader; uplGenericFile.FileName = campaign.GenericFile; } } catch (Exception ex) { // TODO log error lblErrors.Visible = true; lblErrors.ForeColor = Color.Red; lblErrors.Text = "Error occurred: " + ex.Message; } return(campaign); }
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()); }
public bool Create(CampaignCreateApiModel apiModel, int createdUser) { var newCampaign = new CAMPAIGN(); newCampaign.ActualCost = apiModel.actualCost; newCampaign.BudgetedCost = apiModel.budgetedCost; newCampaign.CampaignOwner = apiModel.owner != 0 ? apiModel.owner : createdUser; var dbStatus = db.CAMPAIGN_STATUS.Find(apiModel.status); if (dbStatus != null) { newCampaign.CAMPAIGN_STATUS_ID = apiModel.status; } if (db.CAMPAIGN_TYPE.Find(apiModel.type) != null) { newCampaign.CAMPAIGN_TYPE_ID = apiModel.type; } newCampaign.CreatedAt = DateTime.Now; newCampaign.CreatedBy = createdUser; newCampaign.ModifiedAt = DateTime.Now; newCampaign.Description = apiModel.description; newCampaign.EndDate = DbDateHelper.ToNullIfTooEarlyForDb(apiModel.endDate); newCampaign.ExpectedResponse = apiModel.expectedResponse; newCampaign.ExpectedRevenue = apiModel.expectedRevenue; newCampaign.Name = apiModel.campaignName; newCampaign.NumberSent = apiModel.numberSent; newCampaign.StartDate = DbDateHelper.ToNullIfTooEarlyForDb(apiModel.startDate); newCampaign.EmailTitle = apiModel.emailTitle; try { db.CAMPAIGNs.Add(newCampaign); db.SaveChanges(); var owner = db.USERs.Find(newCampaign.CampaignOwner); var creator = db.USERs.Find(createdUser); var notifyModel = new NotificationApiModel(); notifyModel.title = "Campaign created"; notifyModel.content = $"Campaign {newCampaign.Name} has been created by {creator?.Username}."; notifyModel.createdAt = DateTime.Now; notifyModel.module = "campaigns"; notifyModel.moduleObjectId = newCampaign.ID; NotificationManager.SendNotification(notifyModel, new List <USER> { owner, creator }); return(true); } catch { return(false); } }
public void AddCampaign() { using (var db = new DragonDBModel()) { CAMPAIGN newCampaign = new CAMPAIGN { cmp_name = _view.CampaignTitle, cmp_dm = _view.DungeonMaster, cmp_startdate = DateTime.Now, cmp_description = _view.CampaignDescription }; db.CAMPAIGN.Add(newCampaign); db.SaveChanges(); } }
private string CreateTemplate(AuthenticationDetails auth, string clientID, CAMPAIGN campaign) { string template = string.Empty; try { var htmlText = HttpUtility.HtmlDecode(GenerateTemplateCampaignMonitor(campaign)); var templateID = Helpers.AzureStorageHelper.CreateHtmlTemplateAzure(htmlText); template = Template.Create(auth, clientID, "TEMPLATE " + campaign.Name, templateID, ""); } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } return(template); }
private string GenerateTemplateCampaignMonitor(CAMPAIGN campaign) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); try { sb.Append("<html><head><title>").Append(campaign.Name).Append("</title></head>"); sb.Append("<body><p><singleline>").Append(campaign.Name).Append("</singleline></p>"); sb.Append("<div><multiline>").Append(campaign.AdText).Append("</multiline></div>"); sb.Append("<p><unsubscribe>Unsubscribe</unsubscribe></p></body></html>"); } catch (Exception e) { var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetria.Critical(messageException); } return(sb.ToString()); }
protected void Page_Load(object sender, EventArgs e) { Page.Error += new EventHandler(Page_Error); string idCampaign = Request["ID"]; int id; if (!IsPostBack) { CAMPAIGN campaign = null; if (!String.IsNullOrWhiteSpace(idCampaign) && Int32.TryParse(idCampaign, out id)) { campaign = GetCampaign(id); ID.Value = id.ToString(); if (campaign != null) { brandId.Value = campaign.BrandID.ToString(); btnSelectBrand.Visible = false; } } if (!String.IsNullOrEmpty(User.Identity.Name)) { USER user = ApplicationContext.Current.Users.GetByUserName(User.Identity.Name); // not an administrator neither a moderator if (user.RoleID > 2) { chkApproved.Enabled = false; } } else { chkApproved.Enabled = false; } } txtDateFrom.Attributes.Add("readonly", "readonly"); txtDateTo.Attributes.Add("readonly", "readonly"); txtDeliveryStart.Attributes.Add("readonly", "readonly"); txtDeliveryEnd.Attributes.Add("readonly", "readonly"); txtBrand.Attributes.Add("readonly", "readonly"); txtApprover.Attributes.Add("readonly", "readonly"); txtEncryptedId.Attributes.Add("readonly", "readonly"); }
/// <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"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { gridProduct.SortExp = "Name"; CAMPAIGN campaign = new CAMPAIGN() { SearchStartDate = DateTime.Now.Date.AddMonths(-5), SearchEndDate = DateTime.Now.Date.AddMonths(5) }; int totalRecords; List <CAMPAIGN> campaigns = ApplicationContext.Current.Campaigns.Search(campaign, 10, 0, out totalRecords, "StartDate", BL.Util.SortDirection.Descending).OrderByDescending(c => c.StartDate).ToList(); campaigns.Insert(0, new CAMPAIGN() { ID = -1, Name = "" }); ddlCampaign.DataSource = campaigns; ddlCampaign.DataBind(); } base.Page_Load(sender, e, gridProduct); }
public void Update(CAMPAIGN Entity) { Update(Entity, true); }
public void ChangeApproval(CAMPAIGN Campaign) { _campaignDAO.ChangeApproval(Campaign); }
public void Delete(CAMPAIGN Campaign) { _campaignDAO.Delete(Campaign); Context.SaveChanges(); }
public void Update(CAMPAIGN Campaign, bool Attach = true) { _campaignDAO.Update(Campaign, Attach); Context.SaveChanges(); }
public void Insert(CAMPAIGN Campaign) { _campaignDAO.Insert(Campaign); Context.SaveChanges(); }
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)); }
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"); }
protected void Page_Load(object sender, EventArgs e) { HtmlGenericControl divContent = (HtmlGenericControl)Master.FindControl("divMainContent"); string encCampaignID = RouteData.Values["camp"].ToString(); string encCat = String.Empty; if (RouteData.Values["cat"] == null) { divContent.Attributes["class"] = "ContentII"; imgLogo.Style["margin-top"] = "42px"; } else { divContent.Attributes["class"] = "ContentIII"; encCat = RouteData.Values["cat"].ToString(); } try { string campID = Encryption.Decrypt(encCampaignID); int idCamp; if (Int32.TryParse(campID, out idCamp)) { menuCategory.CampaignID = idCamp; CAMPAIGN campaign = ApplicationContext.Current.Campaigns.GetById(idCamp); if (campaign != null && (campaign.Active || (campaign.Approved.Value && campaign.StartDate > DateTime.Today))) { imgLogo.ImageUrl = Configuration.ImagesUploadPath + campaign.Logo; breadcrumb.CampaignName = campaign.BrandName; this.Title = campaign.BrandName + " - FZone.al"; if (RouteData.Values["cat"] == null) { divContent.Attributes["style"] = "background-image:url('" + Configuration.ImagesUploadPath + campaign.ImageDetail + "');"; } string catID; int iCatId; if (!String.IsNullOrEmpty(encCat)) { catID = Encryption.Decrypt(encCat); if (Int32.TryParse(catID, out iCatId)) { breadcrumb.CategoryID = iCatId; loadProducts(idCamp, iCatId); imgMenuBrand.Visible = true; imgMenuBrand.ImageUrl = Configuration.ImagesUploadPath + campaign.ImageListHeader; } } } else { Response.Redirect("/home"); } } } catch (System.Threading.ThreadAbortException) { } catch (Exception ex) { Log(ex, ex.Message, ex.StackTrace, "Campaign"); Response.Redirect("/home"); } base.Page_Load(sender, e); }
/// <summary> /// Insert new CAMPAIGN element. /// </summary> /// <param name="newCampaign">CAMPAIGN object.</param> public void Insert(CAMPAIGN newCampaign) { Context.CAMPAIGN.AddObject(newCampaign); //Context.SaveChanges(); }
private void loadProductData(string encProdID) { string productId = Encryption.Decrypt(encProdID); int id; if (Int32.TryParse(productId, out id)) { PRODUCT product = ApplicationContext.Current.Products.GetById(id); if (product != null) { CAMPAIGN campaign = null; if (product.CampaignID.HasValue) { campaign = ApplicationContext.Current.Campaigns.GetById(product.CampaignID.Value); } if (campaign != null && (campaign.Active || (campaign.Approved.Value && campaign.StartDate > DateTime.Today))) { ProductID = product.ID; this.Title = campaign.BrandName + " - " + product.Name + " - FZone.al"; litProdCode.Text = product.Code; litOriginalPrice.Text = product.OriginalPrice.ToString("N2"); litPrice.Text = product.OurPrice.ToString("N2"); litDescription.Text = product.Description; litProdName.Text = product.Name; litProdName2.Text = product.Name; loadImages(product); breadcrumb.ProductID = ProductID; breadcrumb.ProductName = product.Name; breadcrumb.CampaignName = campaign.BrandName; breadcrumb.CampaignID = product.CampaignID.Value; CATEGORY cat = product.CATEGORY.Where(c => c.ParentID != null).FirstOrDefault(); if (cat != null) { breadcrumb.CategoryID = cat.ID; breadcrumb.CategoryName = cat.Name; } setCampaignImg(product, campaign); loadProductAttributes(); if (product.Remaining == 0) { divWhenAvailable.Visible = false; litNotAvailable.Visible = true; } } else { Response.Redirect("/home/"); } } else { Response.Redirect("/"); } } else { Response.Redirect("/"); } }
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()); }
private void Save() { CAMPAIGN campaign = new CAMPAIGN(); campaign.Name = txtName.Text; int bId = 0; if (!String.IsNullOrWhiteSpace(brandId.Value) && Int32.TryParse(brandId.Value, out bId)) { campaign.BrandID = bId; } else { lblErrors.Visible = true; lblErrors.ForeColor = Color.Red; lblErrors.Text = "Associated brand is not correct."; return; } campaign.Description = txtDesc.Text; campaign.StartDate = DateTime.Parse(txtDateFrom.Text + " " + txtTimeFrom.Text); campaign.EndDate = DateTime.Parse(txtDateTo.Text + " " + txtTimeTo.Text); if (!String.IsNullOrWhiteSpace(txtDeliveryStart.Text)) { campaign.DeliveryStartDate = DateTime.Parse(txtDeliveryStart.Text); } if (!String.IsNullOrWhiteSpace(txtDeliveryEnd.Text)) { campaign.DeliveryEndDate = DateTime.Parse(txtDeliveryEnd.Text); } if (!String.IsNullOrWhiteSpace(uplLogo.FileName)) { if (uplLogo.FileName.Contains("/")) { campaign.Logo = uplLogo.FileName.Substring(uplLogo.FileName.LastIndexOf("/") + 1); } else { campaign.Logo = uplLogo.FileName; } } if (!String.IsNullOrWhiteSpace(uplHome.FileName)) { if (uplHome.FileName.Contains("/")) { campaign.ImageHome = uplHome.FileName.Substring(uplHome.FileName.LastIndexOf("/") + 1); } else { campaign.ImageHome = uplHome.FileName; } } if (!String.IsNullOrWhiteSpace(uplImgDet.FileName)) { if (uplImgDet.FileName.Contains("/")) { campaign.ImageDetail = uplImgDet.FileName.Substring(uplImgDet.FileName.LastIndexOf("/") + 1); } else { campaign.ImageDetail = uplImgDet.FileName; } } if (!String.IsNullOrWhiteSpace(uplImgHeader.FileName)) { if (uplImgHeader.FileName.Contains("/")) { campaign.ImageListHeader = uplImgHeader.FileName.Substring(uplImgHeader.FileName.LastIndexOf("/") + 1); } else { campaign.ImageListHeader = uplImgHeader.FileName; } } if (!String.IsNullOrWhiteSpace(uplGenericFile.FileName)) { if (uplGenericFile.FileName.Contains("/")) { campaign.GenericFile = uplGenericFile.FileName.Substring(uplGenericFile.FileName.LastIndexOf("/") + 1); } else { campaign.GenericFile = uplGenericFile.FileName; } } int id = 0; lblErrors.Visible = true; lblErrors.ForeColor = Color.Green; string operation = String.Empty; try { USER user = null; if (!String.IsNullOrEmpty(User.Identity.Name)) { user = ApplicationContext.Current.Users.GetByUserName(User.Identity.Name); } if (!String.IsNullOrWhiteSpace(ID.Value) && Int32.TryParse(ID.Value, out id) && id != 0) { campaign.ID = id; bool attached = false; if (user != null) { bool?previousStatus = ApplicationContext.Current.Campaigns.GetCampaignApprovalStatus(campaign.ID); if (chkApproved.Checked) { if (previousStatus == null || !previousStatus.Value) { if (user.RoleID <= 2) { campaign.Approved = true; campaign.ApprovedBy = user.ID; ApplicationContext.Current.Campaigns.ChangeApproval(campaign); attached = true; txtApprover.Text = user.Login; } } } else { if (previousStatus.HasValue && previousStatus.Value) { if (user.RoleID <= 2) { campaign.Approved = false; ApplicationContext.Current.Campaigns.ChangeApproval(campaign); attached = true; txtApprover.Text = String.Empty; } } } } ApplicationContext.Current.Campaigns.Update(campaign, !attached); operation = "updated"; } else { if (user != null && chkApproved.Checked) { campaign.Approved = true; campaign.ApprovedBy = user.ID; txtApprover.Text = user.Login; } else { campaign.Approved = false; } ApplicationContext.Current.Campaigns.Insert(campaign); operation = "inserted"; ID.Value = campaign.ID.ToString(); } txtEncryptedId.Text = FashionZone.BL.Util.Encryption.Encrypt(ID.Value); lblErrors.Text = "Campaign " + operation + " correctly."; } catch (Exception ex) { // TODO log error lblErrors.ForeColor = Color.Red; lblErrors.Text = "Error occurred: " + ex.Message; } }
/// <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(); }