Пример #1
0
        public ActionResult Create([Bind(Include = "ProductID,Name,Description,StockKeepingUnit,Quantity,RetailPrice,WholeSalePrice")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Пример #2
0
 public void CreateNewUser(RegisterDB register)
 {
     using (var context = new ECommerceDB())
     {
         context.registerDB.Add(register);
         context.SaveChanges();
     }
 }
Пример #3
0
        public ProductDTO PurchaseProduct(ProductDTO productDTO)
        {
            ProductDB product = new ProductDB();

            UserProductDBModel userProductDBModel = new UserProductDBModel();

            ProductDTO productDTOObj = new ProductDTO();

            using (var context = new ECommerceDB())
            {
                if (context.productDB.Any(x => x.ModelNumber == productDTO.ModelNumber))
                {
                    product = context.productDB.FirstOrDefault(x => x.ModelNumber == productDTO.ModelNumber);

                    if ((product.AvailableQuantity > productDTO.RequiredQuantity) && productDTO.RequiredQuantity != 0)
                    {
                        product.AvailableQuantity -= productDTO.RequiredQuantity;
                        context.SaveChanges();

                        productDTOObj.ModelNumber       = productDTO.ModelNumber;
                        productDTOObj.Price             = productDTO.Price;
                        productDTOObj.Description       = productDTO.Description;
                        productDTOObj.AvailableQuantity = productDTO.AvailableQuantity;
                        productDTOObj.RequiredQuantity  = productDTO.RequiredQuantity;
                        productDTOObj.DeliveryTime      = productDTO.DeliveryTime;

                        userProductDBModel.Email            = productDTO.Email;
                        userProductDBModel.ModelNumber      = productDTO.ModelNumber;
                        userProductDBModel.RequiredQuantity = productDTO.RequiredQuantity;
                        userProductDBModel.Price            = productDTO.Price;
                        userProductDBModel.Description      = productDTO.Description;
                        userProductDBModel.DeliveryTime     = productDTO.DeliveryTime;
                        context.userProductDBModels.Add(userProductDBModel);
                        context.SaveChanges();

                        return(productDTOObj);
                    }

                    return(null);
                }
                return(null);
            }
        }
Пример #4
0
 public ActionResult Create(ECommerce.ViewModels.ProductCategoryCreateViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     using (var db = new ECommerceDB())
     {
         var category = new Models.ProductCategory
         {
             Name = model.Name,
         };
         db.ProductCategories.Add(category);
         db.SaveChanges();
     }
     return(RedirectToAction("Index", "Home", new { area = "" }));
 }
Пример #5
0
 public ActionResult Create(ECommerce.ViewModels.ProductCreateViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     using (var db = new ECommerceDB())
     {
         var product = new Models.Product
         {
             Name        = model.Name,
             CategoryId  = model.CategoryId,
             Price       = model.Price,
             Beskrivning = model.Beskrivning
         };
         db.Products.Add(product);
         db.SaveChanges();
     }
     return(RedirectToAction("Index", "Home", new { area = "" }));
 }