protected void RadSaveButton_Click(object sender, EventArgs e) { DALPortalDataContext dc = new DALPortalDataContext(); certificateBundle bundleOld = dc.certificateBundles.Where(c => c.businessPartnerId.Equals(businessPartnerId) && c.isActive.Equals(true)).SingleOrDefault(); if (bundleOld != null) { if (this.modelId == bundleOld.modelId) { bundleOld.startDate = DateTime.Now; bundleOld.expireDate = validUntilDTP.SelectedDate; bundleOld.previousCertQty = bundleOld.actualCertQty; // bundle.orderedCertQty = (Int32)creditsLeftTxtBox.Value - bundle.previousCertQty; bundleOld.actualCertQty = (Int32)creditsLeftTxtBox.Value; bundleOld.certificatePrice = (Decimal)priceTextBox.Value; bundleOld.isActive = true; // bundleOud.modelId = modelId; bundleOld.companyCode = "ZW"; bundleOld.businessPartnerId = businessPartnerId; } else { bundleOld.isActive = false; certificateBundle bundelNew = new certificateBundle(); bundelNew.startDate = DateTime.Now; bundelNew.expireDate = validUntilDTP.SelectedDate; bundelNew.previousCertQty = bundleOld.actualCertQty; bundelNew.orderedCertQty = 0; bundelNew.actualCertQty = (Int32)creditsLeftTxtBox.Value; bundelNew.certificatePrice = (Decimal)priceTextBox.Value; bundelNew.isActive = true; bundelNew.modelId = modelId; bundelNew.companyCode = "ZW"; bundelNew.businessPartnerId = businessPartnerId; dc.certificateBundles.InsertOnSubmit(bundelNew); } } else { certificateBundle bundelNew = new certificateBundle(); bundelNew.startDate = DateTime.Now; bundelNew.expireDate = validUntilDTP.SelectedDate; bundelNew.previousCertQty = 0; bundelNew.orderedCertQty = 0; bundelNew.actualCertQty = (Int32)creditsLeftTxtBox.Value; bundelNew.certificatePrice = (Decimal)priceTextBox.Value; bundelNew.isActive = true; bundelNew.modelId = modelId; bundelNew.companyCode = "ZW"; bundelNew.businessPartnerId = businessPartnerId; dc.certificateBundles.InsertOnSubmit(bundelNew); } dc.SubmitChanges(); Session["businessPartnerId"] = businessPartnerId; Response.Redirect("~/Pages/CustomerAccountDetails.aspx"); }
private void loadData() { DALPortalDataContext dc = new DALPortalDataContext(); certificateBundle bundleOud = dc.certificateBundles.Where(c => c.businessPartnerId.Equals(bpId) && c.isActive.Equals(true)).SingleOrDefault(); if (bundleOud != null) { creditsPurchasedTxtBox.Value = bundleOud.orderedCertQty; if (bundleOud.usedCertQty != null) { creditsUsedTxtBox.Value = bundleOud.usedCertQty; } } }
private void getData() { DALPortalDataContext dc = new DALPortalDataContext(); certificateBundle bundle = dc.certificateBundles.Where(c => c.businessPartnerId.Equals(businessPartnerId) && c.isActive.Equals(true)).SingleOrDefault(); if (bundle != null) { creditsPurchasedTxtBox.Value = bundle.orderedCertQty; creditsUsedTxtBox.Value = bundle.usedCertQty; creditsLeftTxtBox.Value = bundle.actualCertQty; validUntilDTP.SelectedDate = bundle.expireDate; if (bundle.certificatePrice == null) { priceTextBox.Value = 7.50; } else { priceTextBox.Value = (Double)bundle.certificatePrice; } switch (bundle.modelId) { case 1: btnModel1.Checked = true; break; case 2: btnModel2.Checked = true; break; case 3: btnModel3.Checked = true; break; case 4: btnModel4.Checked = true; break; case 5: btnModel5.Checked = true; break; } this.modelId = bundle.modelId; } }
protected void RadSaveButton_Click(object sender, EventArgs e) { DALPortalDataContext dc = new DALPortalDataContext(); certificateBundle bundleOld = dc.certificateBundles.Where(c => c.businessPartnerId.Equals(bpId) && c.isActive.Equals(true)).SingleOrDefault(); if (bundleOld != null) { bundleOld.isActive = false; } certificateBundle bundelNew = new certificateBundle(); if (bundleOld != null) { bundelNew.previousCertQty = bundleOld.actualCertQty; bundelNew.actualCertQty = (Int32)creditsOrderTxtBox.Value + bundleOld.actualCertQty; bundelNew.orderedCertQty = bundleOld.orderedCertQty + (Int32)creditsOrderTxtBox.Value; bundelNew.certificatePrice = bundleOld.certificatePrice; } else { bundelNew.previousCertQty = 0; bundelNew.actualCertQty = (Int32)creditsOrderTxtBox.Value; bundelNew.orderedCertQty = (Int32)creditsOrderTxtBox.Value; bundelNew.certificatePrice = (decimal)7.50; } bundelNew.startDate = DateTime.Now; bundelNew.expireDate = DateTime.Now.AddYears(1); bundelNew.isActive = true; bundelNew.modelId = 2; bundelNew.companyCode = "ZW"; bundelNew.businessPartnerId = bpId; businessPartner bpProps = dc.businessPartners.Where(c => c.businessPartnerId.Equals(bpId)).Select(c => c).SingleOrDefault(); DocumentCached cashed = new DocumentCached(); cashed.CustomerCode = bpProps.bpCode; cashed.VLCompany = "ZW01"; cashed.DocDate = DateTime.Now; cashed.Comment = "Certificate portal invoice"; DocumentLineCached cashedLine = new DocumentLineCached(); cashedLine.Currency = "EUR"; cashedLine.LineNum = 1; cashedLine.ItemCode = "C"; cashedLine.Quantity = (Int32)creditsOrderTxtBox.Value; cashedLine.UnitOfMeasure = "ST"; cashedLine.Price = (decimal)bundelNew.certificatePrice; cashedLine.ShortText = creditsOrderTxtBox.Value + " ordered on " + DateTime.Now + "."; cashed.Lines.Add(cashedLine); dc.certificateBundles.InsertOnSubmit(bundelNew); dc.SubmitChanges(); XmlToObject.ObjectToXml(cashed, HttpContext.Current.Server.MapPath(Path.Combine(@"~\Files\Outbox", "invoice " + DateTime.Now.Ticks.ToString() + ".xml"))); MembershipUser membershipUser = Membership.GetUser(); if (membershipUser != null) { String emailTemplate = HttpContext.Current.Server.MapPath(Path.Combine(@"~\Files\EmailTemplates", "OrderConfirmation.html")); StreamReader streamReader = new StreamReader(emailTemplate); String mailMessageBody = streamReader.ReadToEnd(); String fromEmailAddress; String subject; String toEmailAddress; mailMessageBody = EmailClass.GetMailParams(mailMessageBody, out fromEmailAddress, out toEmailAddress, out subject); mailMessageBody = mailMessageBody.Replace("{Credits}", membershipUser.UserName); try { MailMessage mailMessage = new MailMessage(); mailMessage.IsBodyHtml = true; mailMessage.From = new MailAddress(fromEmailAddress); mailMessage.To.Add(membershipUser.UserName); mailMessage.Subject = subject; mailMessage.Body = mailMessageBody; SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(mailMessage); } catch (Exception ex) { // TODO: Create errorpage for user Response.Redirect("~/Pages/OrderSuccess.aspx"); } } Session["businessPartnerId"] = bpId; Response.Redirect("~/Pages/OrderSuccess.aspx"); }