コード例 #1
0
        public JsonResult AddToCart(int Id, String Name, Double Price, String Picture, String SizeName)
        {
            String username = HttpContext.Session.GetString("CURRENTUSER");

            if (SizeName.Equals("Search by Size"))
            {
                return(Json(new { success = false }));
            }
            else
            {
                var checkExist = db.TblCart.Where(c => c.ProductId == Id && c.UserId == username).FirstOrDefault();
                if (checkExist != null)
                {
                    checkExist.Quantity = checkExist.Quantity + 1;
                    db.SaveChanges();
                }
                else
                {
                    TblCart cart = new TblCart();
                    cart.ProductId   = Id;
                    cart.ProductName = Name;
                    cart.Price       = Price;
                    cart.Picture     = Picture;
                    cart.SizeName    = SizeName;
                    cart.Quantity    = 1;
                    cart.UserId      = username;
                    db.TblCart.Add(cart);
                    db.SaveChanges();
                }


                return(Json(new { success = true }));
            }
        }
コード例 #2
0
        public bool AddProductCategory(ProductCategoryViewModel model)
        {
            try
            {
                ProductCategory category = new ProductCategory
                {
                    ProductCategoryName = model.ProductCategoryName,
                };

                _context.ProductCategory.Add(category);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #3
0
        public bool AddProductSale(ProductSaleViewModel model)
        {
            try
            {
                ProductSale productSale = new ProductSale
                {
                    ProductId    = model.Id,
                    SalePersonId = model.SalePersonId
                };

                _context.ProductSale.Add(productSale);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #4
0
        public bool AddShop(ShopViewModel model)
        {
            try
            {
                Shop shop = new Shop
                {
                    ShopName     = model.ShopName,
                    ShopLocation = model.ShopLocation
                };

                _context.Shop.Add(shop);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #5
0
        public bool AddSalePerson(SalePersonViewModel model)
        {
            try
            {
                SalePerson salesPerson = new SalePerson
                {
                    Surname   = model.Surname,
                    OtherName = model.Othername,
                    Gender    = model.Gender.ToString(),
                    ShopId    = model.ShopId
                };

                _context.SalePerson.Add(salesPerson);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #6
0
        public bool AddProduct(ProductViewModel model)
        {
            try
            {
                ProductImage image   = new ProductImage();
                Product      product = new Product();
                if (model.ProductImage != null)
                {
                    byte[] imageByte;

                    using (var memoryStream = new MemoryStream())
                    {
                        model.ProductImage.CopyTo(memoryStream);
                        imageByte = memoryStream.ToArray();
                    }

                    image = new ProductImage
                    {
                        Image = imageByte
                    };

                    _context.ProductImage.Add(image);
                    _context.SaveChanges();
                    product.ProductImageId = image.ProductImageId;
                }

                product.ProductName       = model.ProductName;
                product.Price             = model.Price;
                product.SerialNumber      = model.SerialNumber;
                product.ProductCategoryId = model.ProductCategoryID;
                product.ShopId            = model.ShopID;


                _context.Product.Add(product);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }