public object Get(GetLicense request) { var license = documentSession .Include <Model.License, Customer>(lic => lic.CustomerId) .Include <Product>(lic => lic.ProductId) .Load <Model.License>(request.Id); if (license == null) { HttpError.NotFound("License not found!"); } return(new LicenseDto { Customer = documentSession.Load <Customer>(license.CustomerId), Product = new ProductDto().PopulateWith(documentSession.Load <Product>(license.ProductId)) }.PopulateWith(license)); }
public object Get(GetLicense request) { var license = documentSession .Include<Model.License, Customer>(lic => lic.CustomerId) .Include<Product>(lic => lic.ProductId) .Load<Model.License>(request.Id); if (license == null) HttpError.NotFound("License not found!"); return new LicenseDto { Customer = documentSession.Load<Customer>(license.CustomerId), Product = new ProductDto().PopulateWith(documentSession.Load<Product>(license.ProductId)) }.PopulateWith(license); }
// Gets License, updates SQL, sends Email bool GrabLicense(List <CartItem> cart, Info info, int orderId, Dictionary <string, Dictionary <string, object> > data) { // Get num of Licenses int numL = cart.Select(v => v._num).Sum(); // Create Licenses GetLicense GL = new GetLicense(_sql); var licenses = new int[numL].Select(v => GL.GetIt()).ToList(); if (_sql.State == ConnectionState.Closed) { _sql.Open(); // Re-Check } // SQL Submit each License int ix = 0; foreach (var item in cart) { for (int i = 0; i < item._num; i++) { var com = new SqlCommand("INSERT INTO [License] ([License],[userid],[user],[orderId],[model])" + "VALUES (@License,@userid,@user,@orderId,@model)", _sql); com.Parameters.AddWithValue("@License", licenses[ix++].ToUpper()); com.Parameters.AddWithValue("@userid", info.id); com.Parameters.AddWithValue("@user", info.Email); com.Parameters.AddWithValue("@orderId", orderId); com.Parameters.AddWithValue("@model", item._model); if (com.ExecuteNonQuery() == 0) { throw new Exception(info.Email); } } } // Send Email ------------- string header = $"Thank You for Your Order!"; string msg = $"<p>Order#: {orderId}<br />Total: ${GetTotal(cart)}<br />Date: {DateTime.Now}</p>\n"; msg += $"<p>Thank you for your order {info.First}!</p>\n" + "<p>Here are your purchased License(s):</p>\n"; ix = 0; // Loop Each Item to get each License msg += "<p>"; foreach (var item in cart) { msg += data[item._model]["description"] + ":<br />"; for (int i = 0; i < item._num; i++) { msg += "  " + licenses[ix++].ToUpper() + "<br />"; } } msg += "</p>\n"; msg += "<p><b>NOTE!:</b> Please be sure to keep these Licenses in a safe place.</p>"; msg += "<p><b>To Activate Product:</b>If you have not already done so, please go to the page of the product you purchased and download the software. Then, copy and paste " + "the current License above into the "License" field to Activate the software.</p>"; // HTML Template string html = System.IO.File.ReadAllText(Data._otherFiles + "/Email.html"); html = html.Replace("[[*header*]]", header).Replace("[[*body*]]", msg); // Send Email: Func Starts new Task to send Email Data.SendEmail("Your Order at SupraCharger.com", html, info.Email, isBodyHtml: true); // Return return(true); }