Beispiel #1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Description,Units_Id,Barcode,BuyPrice,ForSale,SellPrice,Notes,Active")] ProductsModels productsModels)
        {
            var check = db.Products.AsNoTracking().Where(x =>
                                                         x.Id != productsModels.Id &&
                                                         x.Description == productsModels.Description &&
                                                         x.Units_Id == productsModels.Units_Id).ToList();

            if (check.Count > 0)
            {
                ModelState.AddModelError("Duplicate", "This Product already existed.");
            }

            if (ModelState.IsValid)
            {
                var current_data = await db.Products.FindAsync(productsModels.Id);

                current_data.Description     = productsModels.Description;
                current_data.Units_Id        = productsModels.Units_Id;
                current_data.Barcode         = productsModels.Barcode;
                current_data.BuyPrice        = productsModels.BuyPrice;
                current_data.ForSale         = productsModels.ForSale;
                current_data.SellPrice       = productsModels.SellPrice;
                current_data.Notes           = productsModels.Notes;
                current_data.Active          = productsModels.Active;
                db.Entry(current_data).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.listUnit = new SelectList(db.Units.Where(x => x.Active == true).OrderBy(x => x.Name), "Id", "Name");
            return(View(productsModels));
        }
Beispiel #2
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Description,Units_Id,Barcode,BuyPrice,ForSale,SellPrice,Notes")] ProductsModels productsModels)
        {
            var check = db.Products.AsNoTracking().Where(x =>
                                                         x.Description == productsModels.Description &&
                                                         x.Units_Id == productsModels.Units_Id).ToList();

            if (check.Count > 0)
            {
                ModelState.AddModelError("Duplicate", "This Product already existed.");
            }

            if (ModelState.IsValid)
            {
                productsModels.Id     = Guid.NewGuid();
                productsModels.Active = true;
                db.Products.Add(productsModels);

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.listUnit = new SelectList(db.Units.Where(x => x.Active == true).OrderBy(x => x.Name), "Id", "Name");
            return(View(productsModels));
        }
Beispiel #3
0
        public async Task <ActionResult> Edit(Guid?id)
        {
            Permission p    = new Permission();
            bool       auth = p.IsGranted(User.Identity.Name, this.ControllerContext.RouteData.Values["controller"].ToString() + "_" + this.ControllerContext.RouteData.Values["action"].ToString());

            if (!auth)
            {
                return(new ViewResult()
                {
                    ViewName = "Unauthorized"
                });
            }
            else
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                ProductsModels productsModels = await db.Products.FindAsync(id);

                if (productsModels == null)
                {
                    return(HttpNotFound());
                }
                ViewBag.listUnit = new SelectList(db.Units.Where(x => x.Active == true).OrderBy(x => x.Name), "Id", "Name");
                return(View(productsModels));
            }
        }
        public ActionResult Create([Bind(Include = "Id,ProductName,NormalPriece,CurrentPrice,Stock,Details,Pruducer,Type")] ProductsModels productsModels)
        {
            if (ModelState.IsValid)
            {
                productsModels.AddDate = DateTime.Now;
                var name  = productsModels.ProductName;
                var price = productsModels.NormalPriece;
                db.ProductsModels.Add(productsModels);
                db.SaveChanges();

                var product = db.ProductsModels.Where(s => s.ProductName == name).Where(d => d.NormalPriece == price).SingleOrDefault();

                string path1 = Server.MapPath("~/ProductsImages/") + product.Id + "/";

                if (!Directory.Exists(path1))
                {
                    Directory.CreateDirectory(path1);
                }


                product.ImagePath = path1;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(productsModels));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ProductsModels productsModels = db.ProductsModels.Find(id);

            db.ProductsModels.Remove(productsModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,ProductName,NormalPriece,CurrentPrice,Stock,Details,AddDate,Pruducer,Type,ImagePath")] ProductsModels productsModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productsModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productsModels));
 }
        public void UpdateProduct(ProductsModels product)
        {
            Product dbProducts = dbContext.Products.FirstOrDefault(x => x.ProductCodeID == product.ProductCode);

            if (product != null)
            {
                dbProducts.ProductCodeID = product.ProductCode;
                dbProducts.ProductName   = product.ProductName;
                dbProducts.Details       = product.Details;
                dbProducts.Price         = product.Price;
                dbProducts.ImageName     = product.ImageName;
                dbContext.SubmitChanges();
            }
        }
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductsModels productsModels = db.ProductsModels.Find(id);

            if (productsModels == null)
            {
                return(HttpNotFound());
            }
            return(View(productsModels));
        }
        private Product MapModelToDbObject(ProductsModels product)
        {
            Product dbProducts = new Product();

            if (product != null)
            {
                dbProducts.ProductCodeID = product.ProductCode;
                dbProducts.ProductName   = product.ProductName;
                dbProducts.Details       = product.Details;
                dbProducts.Price         = product.Price;
                dbProducts.ImageName     = product.ImageName;
                return(dbProducts);
            }
            return(null);
        }
        private ProductsModels MapDbObjectsToModel(Product dbProducts)
        {
            ProductsModels productsModels = new ProductsModels();

            if (dbProducts != null)
            {
                productsModels.ProductCode = dbProducts.ProductCodeID;
                productsModels.ProductName = dbProducts.ProductName;
                productsModels.Details     = dbProducts.Details;
                productsModels.Price       = dbProducts.Price;
                productsModels.ImageName   = dbProducts.ImageName;
                return(productsModels);
            }
            return(null);
        }
Beispiel #11
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                ProductsModels productModels = new ProductsModels();
                UpdateModel(productModels);

                productRepository.UpdateProduct(productModels);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("EditProduct"));
            }
        }
Beispiel #12
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                ProductsModels productModel = new ProductsModels();
                UpdateModel(productModel);

                productRepository.InsertProduct(productModel);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("CreateProduct"));
            }
        }
Beispiel #13
0
        public ActionResult Create(int id, FormCollection collection)
        {
            try
            {
                ProductsModels     productsModels    = productRepository.GetProductById(id);
                ShoppingCartModels shoppingCartModel = new ShoppingCartModels();
                UpdateModel(shoppingCartModel);
                shoppingCartModel.OrderID       = orderChartRepository.LastOrder();
                shoppingCartModel.ProductCodeID = productsModels.ProductCode;
                shoppingCartModel.Price         = productsModels.Price * shoppingCartModel.Quantity;
                shoppingCartRepository.InsertShoppingCart(shoppingCartModel);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("CreateShoppingCart"));
            }
        }
 public void InsertProduct(ProductsModels product)
 {
     dbContext.Products.InsertOnSubmit(MapModelToDbObject(product));
     dbContext.SubmitChanges();
 }
Beispiel #15
0
        // GET: Products/Delete/5
        public ActionResult Delete(int id)
        {
            ProductsModels product = productRepository.GetProductById(id);

            return(View("DeleteProduct", product));
        }
Beispiel #16
0
        // GET: Products/Details/5
        public ActionResult Details(int id)
        {
            ProductsModels productDetails = productRepository.GetProductById(id);

            return(View("ProductDetails", productDetails));
        }