Пример #1
0
 public IActionResult Catalog(CatalogProductVM _catatlog)
 {
     if (_catatlog.sort == null || _catatlog.sort == "")
     {
         catalog.items      = _catatlog.items;
         checkOut.itemForms = catalog.items;
         return(RedirectToAction("Checkout", "User"));
     }
     else
     {
         catalog.sort = _catatlog.sort;
         if (catalog.sort == "asc-price")
         {
             catalog.products.Sort((a, b) => Convert.ToInt32(a.product.price).CompareTo(Convert.ToInt32(b.product.price)));
         }
         else if (catalog.sort == "desc-price")
         {
             catalog.products.Sort((a, b) => Convert.ToInt32(b.product.price).CompareTo(Convert.ToInt32(a.product.price)));
         }
         else
         {
             catalog.products.Sort((a, b) => a.product.name.CompareTo(b.product.name));
         }
         return(View(catalog));
     }
 }
Пример #2
0
        public UserController(ShopDatabaseContext context)
        {
            this.db      = context;
            products     = db.Product.ToList();
            productSizes = db.ProductSize.ToList();
            images       = db.Image.ToList();
            if (category_filters == null || category_filters.Count() == 0)
            {
                category_filters = new List <string>();
            }
            if (size_filters == null || size_filters.Count() == 0)
            {
                size_filters = new List <string>();
            }
            if (price_filters == null || price_filters.Count() == 0)
            {
                price_filters = new List <int>();
            }

            if (cart_products == null || cart_products.Count() == 0)
            {
                cart_products = new List <Product>();
            }
            if (cart_items == null || cart_items.Count == 0)
            {
                cart_items = new List <ItemForm>();
            }
            if (wish_products == null || wish_products.Count() == 0)
            {
                wish_products = new List <Product>();
            }
            if (detail_products == null || detail_products.Count() == 0)
            {
                detail_products = new List <Product>();
            }
            if (cart_images == null || cart_images.Count() == 0)
            {
                cart_images = new List <Image>();
            }
            if (wish_images == null || wish_images.Count() == 0)
            {
                wish_images = new List <Image>();
            }
            if (detail_images == null || detail_images.Count() == 0)
            {
                detail_images = new List <Image>();
            }
            if (customer == null)
            {
                account = new PersonalAccountVM()
                {
                    customer = new Customer()
                    {
                        id       = 0,
                        username = ""
                    },
                    first_name = "",
                    last_name  = "",
                    date       = 1,
                    id         = 0
                };

                address = new PersonalAddressVM()
                {
                    addresses      = new List <Address>(),
                    company_name   = "",
                    country        = "",
                    address_line_1 = "",
                    address_line_2 = "",
                    city           = "",
                    ZIPcode        = "",
                    mobile_phone   = "",
                };
            }
            else
            {
                account = new PersonalAccountVM()
                {
                    customer   = customer,
                    first_name = customer.fullName.Split('_')[0],
                    last_name  = customer.fullName.Split('_')[1],
                    id         = customer.id
                };
                address = new PersonalAddressVM()
                {
                    addresses      = db.Address.Where(a => a.customer == customer.id).ToList(),
                    company_name   = "",
                    country        = "",
                    address_line_1 = "",
                    address_line_2 = "",
                    city           = "",
                    ZIPcode        = "",
                    mobile_phone   = "",
                };
            }
            if (customer != null && customer.id != 0)
            {
                checkOut             = new CheckOutVM();
                checkOut.last_name   = customer.fullName.Split('_')[1];
                checkOut.first_name  = customer.fullName.Split('_')[0];
                checkOut.email       = customer.email;
                checkOut.order_items = new List <Product>();
                checkOut.itemForms   = new List <ItemForm>();

                List <Address> adds = db.Address.Where(a => a.customer == customer.id).ToList();
                if (adds.Count != 0)
                {
                    Address defa = adds.Where(a => a.isDefaultAddress == true).FirstOrDefault();
                    if (defa == null)
                    {
                        defa = adds[0];
                    }
                    checkOut.company_name   = defa.detail.Split('_')[0];
                    checkOut.address_line_1 = defa.detail.Split('_')[1];
                    checkOut.address_line_2 = defa.detail.Split('_')[2];
                    checkOut.city           = defa.detail.Split('_')[3];
                    checkOut.country        = defa.detail.Split('_')[4];
                    checkOut.mobile_phone   = defa.phone;
                }
            }
            else
            {
                checkOut             = new CheckOutVM();
                checkOut.order_items = new List <Product>();
                checkOut.itemForms   = new List <ItemForm>();
            }
            if (customer == null)
            {
                customer = new Customer()
                {
                    fullName = "_",
                    id       = 0,
                };
            }
            if (login == null)
            {
                login = new LoginVM()
                {
                    username   = "",
                    password   = "",
                    isLoggedIn = false,
                };
            }
            if (catalog == null)
            {
                catalog       = new CatalogProductVM();
                catalog.items = new List <ItemForm>();
            }
            initCatalog(products, productSizes, images);
        }