// GET: Orders
        public async Task <IActionResult> WeHaveYourOrder()
        {
            Guid id = Guid.Parse(HttpContext.Session.GetString("myOrder"));

            if (id == null)
            {
                return(NotFound());
            }
            WeHaveYourOrderViewModel viewModel = await GetViewModel((Guid)id);

            viewModel.Email = User.Identity.Name;
            string subject     = "Deine Bestellung bei marelibuDesign";
            string mailContent = await CreateOrderMail(viewModel.OrderID);

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

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

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

            var attachments = new List <string> {
                agb.Filename, wiederuf.Filename, datenschutz.Filename
            };

            logger.LogDebug("WeHaveYourOrderViewModel -> try to send email", null);

            await _emailSender.SendEmailWithAttachmentsAsync(User.Identity.Name, subject, mailContent, attachments);

            await _emailSender.SendEmailAsync("*****@*****.**", "Du hast etwas auf marelibudesign.de verkauft", $"<p>Verkauf an: {User.Identity.Name}</p>");

            //ViewData["Landing"] = viewModel;

            return(View(viewModel));
        }
        private async Task <WeHaveYourOrderViewModel> GetViewModel(Guid id)
        {
            var myorder = await _context.Orders.SingleAsync(o => o.ID == id);

            var paymend = await _context.Paymends.SingleAsync(p => p.ID == myorder.PaymentID);

            var shippingAddress = await _context.ShippingAddresses.SingleAsync(a => a.ID == myorder.ShippingAddressId);

            var invioceAddress = await _context.ShippingAddresses.FirstOrDefaultAsync(a => a.CustomerID == myorder.CustomerID && a.IsInvoiceAddress);

            var period = await _context.ShpippingPeriods.SingleAsync(p => p.ShippingPeriodID == myorder.ShippingPeriodId);

            var shipPrice = await _context.ShippingPrices.SingleAsync(p => p.ID == myorder.ShippingPriceId);

            var olines = await _context.OrderLines.Where(ol => ol.OrderID.Equals(myorder.ID)).ToListAsync();

            List <WeHaveYourOrderLineViewModel> lineViewModels = new List <WeHaveYourOrderLineViewModel>();

            foreach (var item in olines)
            {
                var prod = await _context.Products.SingleAsync(p => p.ProductID == item.ProductID);

                var img = await _context.ProductImages.SingleAsync(p => p.IsMainImage && p.ProductID == item.ProductID);

                var unit = await _context.Units.SingleAsync(u => u.UnitID == prod.BasesUnitID);

                var line = new WeHaveYourOrderLineViewModel
                {
                    ID            = item.OrderLineID,
                    ImagePath     = img.ImageUrl,
                    Position      = item.Position,
                    Price         = Math.Round((item.SellBasePrice * item.Quantity), 2),
                    ProductName   = prod.Name,
                    ProductNumber = prod.ProductNumber,
                    Quantity      = Math.Round(item.Quantity, 2),
                    ProductUnit   = unit.Name
                };

                lineViewModels.Add(line);
            }


            BankAcccount bank = null;

            var shipTo = addressHelper.GetViewModel(shippingAddress);

            ShippingAddressViewModel invoiceVm = null;

            if (invioceAddress == null)
            {
                var customer = await _context.Customers.SingleAsync(c => c.CustomerID == myorder.CustomerID);

                invoiceVm = addressHelper.GetViewModel(customer);
            }
            else
            {
                invoiceVm = addressHelper.GetViewModel(invioceAddress);
            }

            string thankyou = await GetThankyou(paymend);

            WeHaveYourOrderViewModel viewModel = new WeHaveYourOrderViewModel
            {
                OrderID              = myorder.ID,
                OrderDate            = myorder.OrderDate,
                OrderNo              = myorder.Number,
                OrderPaymend         = paymend.Name,
                OrderShippingAddress = shipTo,
                OrderInvoiceAddress  = invoiceVm,
                OrderShippingPeriod  = period.Decription,
                Bank          = bank,
                OrderTotal    = Math.Round(myorder.Total, 2),
                OrderThankYou = thankyou,
                ShipPrice     = Math.Round(myorder.ShippingPrice, 2),
                ShipPriceName = shipPrice.Name,
                OrderLines    = lineViewModels,
                FreeText      = myorder.FreeText
            };

            return(viewModel);
        }