Пример #1
0
        public async Task <IActionResult> Create([Bind("ID,Name,Filename,ShopFileType,IsActive")] ShopFile shopFile)
        {
            if (ModelState.IsValid)
            {
                var files = HttpContext.Request.Form.Files;
                if (files != null && files.Count > 0)
                {
                    var file   = files.First();
                    var helper = new UploadHelper(_environment);
                    var fnames = await helper.FileUploadAsync(file, "files", false);

                    shopFile.Name     = fnames.Name;
                    shopFile.Filename = fnames.Filename;
                }
                _context.Add(shopFile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shopFile));
        }
        public async Task <IActionResult> Create([Bind("ProductImageID,Name,IsMainImage,ImageUrl,ProductID")] ProductImage productImage)
        {
            if (ModelState.IsValid)
            {
                var files = HttpContext.Request.Form.Files;
                foreach (var image in files)
                {
                    if (image != null && image.Length > 0)
                    {
                        var file = image;
                        if (file.Length > 0)
                        {
                            try
                            {
                                UploadHelper helper = new UploadHelper(_environment);
                                var          names  = await helper.FileUploadAsync(file, "images/store", true);

                                productImage.ImageUrl = names.Filename;
                                productImage.Name     = names.Name;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                            }
                        }
                    }
                }

                _context.Add(productImage);
                await _context.SaveChangesAsync();

                return(Redirect("/Admin/Products/Details?id=" + productImage.ProductID));
            }
            ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductID", productImage.ProductID);
            return(View(productImage));
        }
        public async Task <IActionResult> EMailSend([Bind("OrderID, Email, Subject, Message, Attachments")] OrderEmailViewModel orderEmail)
        {
            if (ModelState.IsValid)
            {
                OrderViewModel vm   = null;
                BankAcccount   bank = null;

                if (orderEmail.OrderID == null)
                {
                    return(NotFound());
                }
                else
                {
                    vm = await GetOrderViewModel(orderEmail.OrderID);

                    bank = await _context.BankAcccounts.FirstOrDefaultAsync();

                    string bill = $"<h2>Hallo Frau/Herr {vm.CutomerLastName},</h2>" +
                                  $"<p>noch einmal vielen Dank für Ihren Einkauf.</p>" +
                                  $"<p>Bitte überweisen Sie den Gesamtbetrag von <b>{Math.Round(vm.Total, 2)} &euro;</b> innerhalb von 7 Tagen unter Angabe der Rechungsnummer:<br/>" +
                                  $"<b>{orderEmail.Message}</b><br />" +
                                  $"auf das folgende Konto:</p>" +
                                  $"<br />" +
                                  $"<p>Kontoinhaber:<b> {bank.AccountOwner}</b><br />" +
                                  $"IBAN: <b>{bank.Iban}</b><br />" +
                                  $"SWIFT-BIC: <b>{bank.SwiftBic}</b><br />" +
                                  $"Bank: <b>{bank.Institute}</b></p><br />";
                    bill += $"<hr /><h3>Rechungsdetails</h3>" +
                            $"<p>Ihre Bestellung vom {vm.OrderDate.ToShortDateString()}</p>";
                    if (!string.IsNullOrWhiteSpace(vm.FreeText))
                    {
                        bill += $"<p>Ihre Angaben zur Bestellung: <b>{vm.FreeText}</b></p>";
                    }
                    bill += $"<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" height=\"15%\" width=\"75%\"><tr><th>Position</th><th>Artikel-Nr.</th><th>Artikelname</th><th>Menge</th><th>Betrag</th></tr>";
                    foreach (var item in vm.OderLines)
                    {
                        bill += $"<tr><td align=\"center\">{item.Position}</td>" +
                                $"<td align=\"center\">{item.ProductNumber}</td>" +
                                $"<td align=\"center\">{item.ProductName}</td>" +
                                $"<td align=\"center\">{Math.Round(item.OrderQuantity, 2)} {item.OrderUnit}</td>" +
                                $"<td align=\"center\">{Math.Round(item.OrderLineTotal,2)} &euro;</td></tr>";
                    }
                    bill += $"</table><br />" +
                            $"<table cellpadding=\"0\" cellspacing=\"1\" height=\"5%\" width=\"85%\">" +
                            $"<tr>" +
                            $"<td align=\"right\" colspan=\"4\">Versand, {vm.ShippingPriceName}:</td>" +
                            $"<td>{Math.Round(vm.ShippingPriceAtOrder,2)} &euro;</td></tr>" +
                            $"<tr>" +
                            $"<td align=\"right\" colspan=\"4\">Gesamtbetrag:</td><td>{Math.Round(vm.Total,2)} &euro;</td></tr>" +
                            $"</table>" +
                            $"<br />" +
                            $"<p>Die Lieferfrist beginnt mit der Zahlungsanweisung.</p>" +
                            $"<br />" +
                            $"<p>Viele Gr&uuml;&szlig;e,</p><p>Petra Buron</p><br />";
                    var attachments = new List <string>();
                    var files       = HttpContext.Request.Form.Files;
                    if (files != null && files.Count > 0)
                    {
                        //var file = files.First();
                        var helper = new UploadHelper(_environment);
                        var todel  = new List <string>();


                        foreach (var file in files)
                        {
                            var fnames = await helper.FileUploadAsync(file, "files", false);

                            todel.Add(fnames.Filename);
                            attachments.Add(fnames.Filename);
                        }

                        foreach (string file in todel)
                        {
                            helper.DeleteFile("files", file);
                        }
                    }

                    var agb = await _context.ShopFiles.SingleAsync(s => s.ShopFileType == Enums.ShopFileTypeEnum.AGB);

                    var wiederruf = await _context.ShopFiles.SingleAsync(s => s.ShopFileType == Enums.ShopFileTypeEnum.WRB);

                    var datenschutz = await _context.ShopFiles.SingleAsync(s => s.ShopFileType == Enums.ShopFileTypeEnum.DSK);

                    attachments.Add(agb.Filename);
                    attachments.Add(wiederruf.Filename);
                    attachments.Add(datenschutz.Filename);

                    await _emailSender.SendEmailWithAttachmentsAsync(orderEmail.Email, orderEmail.Subject, bill, attachments);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(orderEmail));
        }