public async Task <IActionResult> Create([Bind("ProductOptionId,ProductId,Type,Name,FormFile,Default,StockCode,Disabled")] ProductOption productOption) { if (ModelState.IsValid) { if (productOption.FormFile != null) { MemoryStream ms = new MemoryStream(); await productOption.FormFile.CopyToAsync(ms); productOption.FileName = productOption.FormFile.FileName; productOption.Image = ms.ToArray(); } _context.Add(productOption); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { id = productOption.ProductId })); } productOption.Types = new SelectList(new List <string>() { "Fabric", "Mesh", "Frame", "Arms", "Castors" }); return(View(productOption)); }
public async Task <IActionResult> Create([Bind("ProductId,DealerCode,Ponumber,Chair,FormFile3,Language,FormFile,FormFile2,InstallGuide,UserGuide,VideoUrl,SitFitGuide,VerifyOnly,Shipper,Config")] Product product) { if (ModelState.IsValid) { if (product.FormFile != null) { MemoryStream ms = new MemoryStream(); await product.FormFile.CopyToAsync(ms); product.LogoFile = product.FormFile.FileName; product.LogoImage = ms.ToArray(); } if (product.FormFile2 != null) { MemoryStream ms = new MemoryStream(); await product.FormFile2.CopyToAsync(ms); product.LogoFile2 = product.FormFile2.FileName; product.LogoImage2 = ms.ToArray(); } if (product.FormFile3 != null) { MemoryStream ms = new MemoryStream(); await product.FormFile3.CopyToAsync(ms); product.Image = ms.ToArray(); } _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } product.Languages = new SelectList(new List <string>() { "English", "French" }); product.Shippers = new SelectList(new List <string>() { "FEDEX", "UPS" }); return(View(product)); }
public async Task <IActionResult> Create([Bind("ProductImageId,ProductId,ProductOption1Id,ProductOption2Id,ProductOption3Id,FileName,FormFile")] ProductImage productImage) { if (ModelState.IsValid) { if (productImage.FormFile != null) { MemoryStream ms = new MemoryStream(); await productImage.FormFile.CopyToAsync(ms); productImage.FileName = productImage.FormFile.FileName; productImage.Image = ms.ToArray(); } _context.Add(productImage); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { id = productImage.ProductId })); } return(View(productImage)); }
public async Task <IActionResult> Create([Bind("UserId,ProductId,EmailAddress,Language,Pin,Address1,Address2,City,ProvinceState,PostalZip,Country,SpecialInstructions,Commercial,Emailed,Completed,InProduction,Shipped")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); var product = await _context.Product.FirstOrDefaultAsync(m => m.ProductId == user.ProductId); List <ProductOption> productOptions = await _context.ProductOption.Where(x => x.ProductId == user.ProductId).ToListAsync(); foreach (var item in productOptions) { if (item.Default) { _context.Add(new UserSelection() { UserId = user.UserId, ProductOptionId = item.ProductOptionId, Type = item.Type }); } } await _context.SaveChangesAsync(); if (!string.IsNullOrEmpty(user.Pin) && user.Emailed == null) { string url = _configuration.GetValue <string>("AppSettings:UserUrl") + user.ProductId; string body = "<a href='" + url + "'>Click here</a> to access the site.<br/><br/>Your log in PIN is " + user.Pin + "."; string file = _env.WebRootPath + "\\emails\\email1_" + user.Language + ".txt"; if (product.VerifyOnly) { file = _env.WebRootPath + "\\emails\\email1v_" + user.Language + ".txt"; } StreamReader sr = new StreamReader(file); if (sr != null) { string[] parameters = new string[] { url, user.Pin }; body = string.Format(sr.ReadToEnd(), parameters); sr.Close(); sr.Dispose(); } string subject = "The way we sit matters."; if (user.Language == "French") { subject = "La position dans laquelle nous nous assoyons révèle bien des choses."; } var emessage = new MailMessage("*****@*****.**", user.EmailAddress, subject, body) { IsBodyHtml = true, BodyEncoding = System.Text.Encoding.UTF8 }; emessage.Bcc.Add("*****@*****.**"); emessage.Bcc.Add("*****@*****.**"); using SmtpClient SmtpMail = new SmtpClient("allfs90.allseating.com", 25) { UseDefaultCredentials = true }; SmtpMail.Send(emessage); emessage.Dispose(); user.Emailed = DateTime.Now; _context.Update(user); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } user.Languages = new SelectList(new List <string>() { "English", "French" }); return(View(user)); }