public IActionResult Index() { var productImages = _context.ProductImages.Where(i => i.IsMainImage).ToList(); var urls = new List <string>(); metaService.AddMetadata("description", "Verkauf von Eislaufasseoirs, Stoffen und mehr."); metaService.AddMetadata("keywords", "Asseoirs,Eiskunstlauf,Stoffe,Webrare,Taschen"); cartHelper.CheckAndRemove(); _logger.LogDebug("show home index"); foreach (var item in productImages) { urls.Add(item.ImageUrl); } var model = new HomeViewModel(); model.ImageUrls = urls; return(View(model)); }
// GET: Orders/Create public async Task <IActionResult> Create(Guid?id) { cartHelper.CheckAndRemove(); OrderCreateViewModel vm = new OrderCreateViewModel(); List <ShippingAddress> addresses = new List <ShippingAddress>(); var identity = User.Identity; var currentUser = _userManager.Users.Single(u => u.UserName == identity.Name); var userId = currentUser.Id; var customer = await _context.Customers.Where(c => c.UserId == userId).SingleAsync(); ShippingPrice shippingPriceDefault = null; decimal shipDefaultPrice = 0.0M; int countryDefault = 1; //Country 1 Deutschland int ShippingPeriodDefaultID = 1; if (customer.CustomerID != Guid.Empty) { var shipping = await _context.ShippingAddresses.SingleOrDefaultAsync(c => c.CustomerID == customer.CustomerID && c.IsMainAddress); if (shipping == null) { return(RedirectToAction("CustomerIndex", "ShippingAddresses", new { id = customer.CustomerID })); } countryDefault = shipping.CountryID; } var countries = await _context.Countries.ToListAsync(); var country = countries.Single(c => c.ID == countryDefault); ViewData["CustomerCountryCode"] = country.Code; if (id != null) { Guid cartId = (Guid)id; var shoppingCart = await _context.ShoppingCarts.SingleAsync(sc => sc.ID == id); decimal total = 0.0M; var lines = _context.ShoppingCartLines.Where(l => l.ShoppingCartID.Equals(shoppingCart.ID)); List <CartLineViewModel> vmcLines = new List <CartLineViewModel>(); foreach (var item in lines) { string path = string.Empty; try { path = _context.ProductImages.Where(i => i.ProductID.Equals(item.ProductID) && i.IsMainImage).SingleOrDefault().ImageUrl; } catch (Exception) { path = "noImage.svg"; } var product = _context.Products.Where(p => p.ProductID.Equals(item.ProductID)).SingleOrDefault(); if (ShippingPeriodDefaultID < product.ShippingPeriod) { ShippingPeriodDefaultID = product.ShippingPeriod; } var productShipPrice = await _context.ShippingPrices.SingleAsync(s => s.ShippingPriceTypeId == product.ShippingPriceType && s.CountryId == countryDefault); if (shipDefaultPrice < productShipPrice.Price) { shipDefaultPrice = productShipPrice.Price; shippingPriceDefault = productShipPrice; } decimal baseprice = _context.Products.Where(p => p.ProductID.Equals(item.ProductID)).SingleOrDefault().Price; decimal pPrice = 0.0M; if (baseprice != 0.0M) { pPrice = baseprice * item.Quantity; } if (string.IsNullOrEmpty(path)) { path = "noImage.svg"; } var unitHelper = new UnitHelper(_context, factory); string unit = unitHelper.GetUnitName(product.BasesUnitID); string sekunit = unitHelper.GetUnitName(product.SecondBaseUnit); CartLineViewModel cvml = new CartLineViewModel() { ID = item.ID, CartID = item.ShoppingCartID, ImgPath = path, Position = item.Position, PosPrice = Math.Round(pPrice, 2), Quantity = Math.Round(item.Quantity, 2), ProductID = item.ProductID, Unit = unit, ProductName = product.Name, ProductNo = product.ProductNumber.ToString(), MinimumPurchaseQuantity = Math.Round(product.MinimumPurchaseQuantity, 2), AvailableQuantity = Math.Round(product.AvailableQuantity, 2), ShoppingCartID = shoppingCart.ID, SellBasePrice = Math.Round(item.SellBasePrice, 2), SellSekPrice = Math.Round(product.SecondBasePrice, 2), SekUnit = sekunit, ShortDescription = product.ShortDescription, UnitID = product.BasesUnitID }; vmcLines.Add(cvml); total = total + pPrice; } CartViewModel cvm = new CartViewModel() { ID = shoppingCart.ID, Number = shoppingCart.Number, OrderId = shoppingCart.OrderId, Lines = vmcLines, Total = total, }; addresses = await _context.ShippingAddresses.Where(sh => sh.CustomerID == customer.CustomerID).ToListAsync(); vm.ShippingAddresseVMs = new List <ShippingAddressViewModel>(); int mainShipID = 0; foreach (var item in addresses) { var shipVm = new ShippingAddressViewModel { ID = item.ID, FirstName = item.FirstName, LastName = item.LastName, Address = item.Address, AdditionalAddress = item.AdditionalAddress, PostCode = item.PostCode, City = item.City, CountryID = item.CountryID, CustomerID = item.CustomerID, IsMainAddress = item.IsMainAddress, CountryName = countries.Single(c => c.ID == item.CountryID).Name }; if (shipVm.IsMainAddress) { mainShipID = shipVm.ID; } vm.ShippingAddresseVMs.Add(shipVm); } string strOrderNo = await GetActualOrderNo(); vm.Cart = cvm; vm.Order = new Order(); vm.Order.Number = strOrderNo; vm.Order.CartID = cvm.ID; vm.Order.ShippingAddressId = mainShipID; vm.Order.OrderDate = DateTime.Now; } var paymends = await _context.Paymends.ToListAsync(); ShippingPeriod periodDefault = await _context.ShpippingPeriods.SingleAsync(s => s.ShippingPeriodID == ShippingPeriodDefaultID); vm.Cart.Total = vm.Cart.Total + shipDefaultPrice; vm.Cart.Total = Math.Round(vm.Cart.Total, 2); vm.PayPalTotal = Math.Round(vm.Cart.Total, 2).ToString(CultureInfo.CreateSpecificCulture("en-US")); shipDefaultPrice = Math.Round(shipDefaultPrice); vm.ShippingPrice = shippingPriceDefault; vm.ShippingPeriod = periodDefault; vm.CanBuyWithBill = customer.AllowedPayByBill; ViewData["Paymends"] = paymends; return(View(vm)); }
public async Task <IActionResult> Kategorie([FromQuery] string categoryId, [FromQuery] string categorySubId, [FromQuery] string categoryDetailId) { cartHelper.CheckAndRemove(); string titel = string.Empty; string metadescription = string.Empty; string metakeywords = string.Empty; string categorieDescription = string.Empty; int catId = 0; int catSubId = 0; int catDetId = 0; if (categoryId != null) { string[] catsplit = categoryId.Split("-"); catId = int.Parse(catsplit[0]); } if (categorySubId != null) { string[] catSubSplit = categorySubId.Split("-"); catSubId = int.Parse(catSubSplit[0]); } if (categoryDetailId != null) { string[] catDetSplit = categoryDetailId.Split("-"); catDetId = int.Parse(catDetSplit[0]); } var products = await _context.Products.Include(p => p.ImageList).Include(ca => ca.CategoryAssignments).OrderByDescending(p => p.ProductID).ToListAsync(); List <Product> filterProducts = new List <Product>(); List <ProductThumbnailsViewModel> thubnails = new List <ProductThumbnailsViewModel>(); var categoryAssignments = new List <CategoryAssignment>(); if (catId > 0) { var category = await _context.Categories.Where(c => c.ID == catId).SingleAsync(); titel = category.Name; metadescription = category.SeoDescription; metakeywords = category.SeoKeywords; categorieDescription = category.HtmlDescription; if (catSubId > 0) { var categorySub = await _context.CategorySubs.Where(c => c.ID == catSubId).SingleAsync(); titel += $"-{categorySub.Name}"; metadescription = categorySub.SeoDescription; metakeywords = categorySub.SeoKeywords; categorieDescription = categorySub.HtmlDescription; if (catDetId > 0) { var categoryDetail = await _context.CategoryDetails.Where(c => c.ID == catDetId).SingleAsync(); titel += $"-{categoryDetail.Name}"; metadescription = categoryDetail.SeoDescription; metakeywords = categoryDetail.SeoKeywords; categorieDescription = categoryDetail.HtmlDescription; categoryAssignments = await _context.CategoryAssignments.Where(ca => ca.CategoryID == catId && ca.CategorySubID == catSubId && ca.CategoryDetailID == catDetId).ToListAsync(); } else { categoryAssignments = await _context.CategoryAssignments.Where(ca => ca.CategoryID == catId && ca.CategorySubID == catSubId).ToListAsync(); } } else { categoryAssignments = await _context.CategoryAssignments.Where(ca => ca.CategoryID == catId).ToListAsync(); } if (categoryAssignments.Count > 0) { foreach (CategoryAssignment item in categoryAssignments) { var product = products.Where(p => p.ProductID == item.ProductID && p.MinimumPurchaseQuantity <= p.AvailableQuantity && p.IsActive).FirstOrDefault(); if (product != null) { if (!filterProducts.Contains(product)) { filterProducts.Add(product); } } } } } foreach (Product item in filterProducts) { List <string> urls = new List <string>(); string baseUnit = string.Empty; string secondPriceUnit = string.Empty; ProductThumbnailsViewModel vmProduct = new ProductThumbnailsViewModel(); baseUnit = new UnitHelper(_context, factory).GetUnitName(item.BasesUnitID); if (item.SecondBasePrice != 0.0M && item.SecondBaseUnit != 0) { string strUnit = new UnitHelper(_context, factory).GetUnitName(item.SecondBaseUnit); secondPriceUnit = Math.Round(item.SecondBasePrice, 2).ToString() + " €/" + strUnit; } try { vmProduct.ProductID = item.ProductID; vmProduct.ProductNumber = item.ProductNumber; vmProduct.Price = item.Price; vmProduct.AvailableQuantity = item.AvailableQuantity; vmProduct.BasesUnit = baseUnit; vmProduct.BasesUnitID = item.BasesUnitID; vmProduct.Description = item.Description; vmProduct.MinimumPurchaseQuantity = item.MinimumPurchaseQuantity; vmProduct.Name = item.Name; vmProduct.ShippingTime = new ShippingPeriodHelper(_context).GetDescription(item.ShippingPeriod); vmProduct.Size = new SizeHelper(_context).GetName(item.Size); vmProduct.ShortDescription = item.ShortDescription; vmProduct.SecondPriceUnit = secondPriceUnit; vmProduct.SlugUrl = $"{item.ProductID}-{item.ProductNumber}-{FriendlyUrlHelper.ReplaceUmlaute(item.Name)}"; } catch (Exception ex) { Console.WriteLine(ex); } foreach (ProductImage img in item.ImageList) { if (img.IsMainImage) { vmProduct.MainImageUrl = img.ImageUrl; } urls.Add(img.ImageUrl); } if (string.IsNullOrEmpty(vmProduct.MainImageUrl)) { if (urls.Count > 0) { vmProduct.MainImageUrl = urls.First(); } else { vmProduct.MainImageUrl = "noImage.svg"; } } vmProduct.ImageUrls = urls; thubnails.Add(vmProduct); } ViewData["CategorieDescription"] = categorieDescription; ViewData["Title"] = titel; if (!string.IsNullOrWhiteSpace(metadescription)) { metaService.AddMetadata("description", metadescription); } if (!string.IsNullOrWhiteSpace(metakeywords)) { metaService.AddMetadata("keywords", metakeywords); } thubnails.Shuffle(); return(View(thubnails)); }
// GET: ShoppingCarts/Details/5 public async Task <IActionResult> Details(Guid?id) { var sessioncart = HttpContext.Session.GetString("ShoppingCartId"); int shipTypeDefault = 1; //Type 1 = kleines Paket decimal shipDefaultPrice = 0.0M; int countryDefault = 1; //Country 1 Deutschland int periodDefault = 1; if (id == null) { return(NotFound()); } var shoppingCart = await _context.ShoppingCarts.SingleOrDefaultAsync(m => m.ID == id); if (shoppingCart == null) { return(NotFound()); } if (shoppingCart.CustomerId != Guid.Empty) { var shipping = await _context.ShippingAddresses.SingleOrDefaultAsync(c => c.CustomerID == shoppingCart.CustomerId && c.IsMainAddress); if (shipping == null) { return(RedirectToAction("CustomerIndex", "ShippingAddresses", new { id = shoppingCart.CustomerId })); } countryDefault = shipping.CountryID; } decimal total = 0.0M; var lines = _context.ShoppingCartLines.Where(l => l.ShoppingCartID.Equals(shoppingCart.ID)); List <CartLineViewModel> vmcLines = new List <CartLineViewModel>(); foreach (var item in lines) { string path = string.Empty; try { path = _context.ProductImages.Where(i => i.ProductID.Equals(item.ProductID) && i.IsMainImage).SingleOrDefault().ImageUrl; } catch (Exception) { path = "noImage.svg"; } var product = _context.Products.Where(p => p.ProductID.Equals(item.ProductID)).SingleOrDefault(); if (periodDefault < product.ShippingPeriod) { periodDefault = product.ShippingPeriod; } var productShipPrice = await _context.ShippingPrices.SingleAsync(s => s.ShippingPriceTypeId == product.ShippingPriceType && s.CountryId == countryDefault); if (shipDefaultPrice < productShipPrice.Price) { shipDefaultPrice = productShipPrice.Price; shipTypeDefault = productShipPrice.ShippingPriceTypeId; } decimal baseprice = _context.Products.Where(p => p.ProductID.Equals(item.ProductID)).SingleOrDefault().Price; decimal pPrice = 0.0M; if (baseprice != 0.0M) { pPrice = baseprice * item.Quantity; } if (string.IsNullOrEmpty(path)) { path = "noImage.svg"; } string unit = new UnitHelper(_context, factory).GetUnitName(product.BasesUnitID); string sekunit = new UnitHelper(_context, factory).GetUnitName(product.SecondBaseUnit); CartLineViewModel cvml = new CartLineViewModel() { ID = item.ID, CartID = item.ShoppingCartID, ImgPath = path, Position = item.Position, PosPrice = pPrice, Quantity = item.Quantity, ProductID = item.ProductID, Unit = unit, UnitID = item.UnitID, ProductName = product.Name, ProductNo = product.ProductNumber.ToString(), ShortDescription = product.ShortDescription, MinimumPurchaseQuantity = Math.Round(product.MinimumPurchaseQuantity, 2), AvailableQuantity = Math.Round(product.AvailableQuantity, 2), ShoppingCartID = shoppingCart.ID, SellBasePrice = Math.Round(item.SellBasePrice, 2), SellSekPrice = Math.Round(product.SecondBasePrice, 2), SekUnit = sekunit, SlugUrl = $"{item.ProductID}-{product.ProductNumber}-{FriendlyUrlHelper.ReplaceUmlaute(product.Name)}" }; vmcLines.Add(cvml); total = total + pPrice; } ShippingPeriod shippingPeriod = await _context.ShpippingPeriods.SingleAsync(s => s.ShippingPeriodID == periodDefault); total = total + shipDefaultPrice; shipDefaultPrice = Math.Round(shipDefaultPrice, 2); var shippreise = await new ShippingPricesHelpers(_context).GetShippingPricesViewModels(shipTypeDefault); CartViewModel vm = new CartViewModel() { ID = shoppingCart.ID, Number = shoppingCart.Number, OrderId = shoppingCart.OrderId, Lines = vmcLines, Total = total, DefaultCountry = countryDefault, ShipPrices = shippreise, ShippingPeriodName = shippingPeriod.Decription }; cartHelper.CheckAndRemove(); return(View(vm)); }