public ActionResult Create([Bind(Include = "UserId,UserName,UserEmail,UserPhone,UserAddress,UserPassword,RoleId")]
                                   User user, HttpPostedFileBase UserImage)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (UserImage != null)
                    {
                        var    fileName  = Path.GetFileNameWithoutExtension(UserImage.FileName);
                        string extention = Path.GetExtension(UserImage.FileName);
                        fileName = fileName + extention;
                        // store the file inside ~/App_Data/uploads folder
                        var path          = Path.Combine(Server.MapPath("~/App_File/UserImages/"), fileName);
                        var pathforDbSave = "/App_File/UserImages/" + fileName;
                        user.UserImage = pathforDbSave;
                        UserImage.SaveAs(path);
                        db.Users.Add(user);
                        db.SaveChanges();
                    }
                    db.Users.Add(user);
                    db.SaveChanges();
                    return(RedirectToAction("Message"));
                }

                catch (Exception)
                {
                    ViewBag.error = " Failed";
                }
            }

            ViewBag.RoleId = new SelectList(db.Roles, "RoleId", "RoleName", user.RoleId);
            return(View(user));
        }
        public ActionResult Create([Bind(Include = "ProductId,ProductCode,ProductName,CategoryId,ColorId,SizeId,ProductQuantity,AlertQuantity,SellingPrice,Image,ManufactureId,ProductDate")]
                                   Product product, HttpPostedFileBase ProductImage)
        {
            ManufactureProduct manufactureProduct = new ManufactureProduct();


            if (ModelState.IsValid)
            {
                try
                {
                    if (db.Products.Any(a => a.ProductCode == product.ProductCode))
                    {
                        db.Database.ExecuteSqlCommand("UPDATE [dbo].[Product] SET ProductQuantity = ProductQuantity+'" + product.ProductQuantity + "' WHERE ProductCode = '" + product.ProductCode + "'");
                    }

                    else
                    {
                        if (ProductImage != null)
                        {
                            // extract only the filename
                            var    fileName  = Path.GetFileNameWithoutExtension(ProductImage.FileName);
                            string extention = Path.GetExtension(ProductImage.FileName);
                            fileName = fileName + extention;
                            // store the file inside ~/App_Data/uploads folder
                            var path          = Path.Combine(Server.MapPath("~/App_File/ProductImages/"), fileName);
                            var pathforDbSave = "/App_File/ProductImages/" + fileName;
                            product.ProductImage = pathforDbSave;
                            ProductImage.SaveAs(path);
                            db.Products.Add(product);
                            db.SaveChanges();
                        }
                    }
                    ViewBag.FileStatus = "File uploaded successfully.";
                }
                catch (Exception)
                {
                    ViewBag.FileStatus = "Error while file uploading.";
                }

                int id = db.Products.Max(a => a.ProductId);

                db.ManufactureProducts.Add(
                    new ManufactureProduct
                {
                    Quantity            = Convert.ToInt32(product.ProductQuantity),
                    ManufactureDateTime = Convert.ToDateTime(product.ProductDate),
                    ProductId           = id
                }
                    );
                db.SaveChanges();


                return(RedirectToAction("Message", "Products"));
            }
            ViewBag.CategoryId    = new SelectList(db.Categories, "CategoryId", "CategoryName", product.CategoryId);
            ViewBag.ColorId       = new SelectList(db.Colors, "ColorId", "ColorName", product.ColorId);
            ViewBag.ManufactureId = new SelectList(db.Manufactures, "ManufactureId", "LotNumber", product.ManufactureId);
            ViewBag.SizeId        = new SelectList(db.Sizes, "SizeId", "SizeName", product.SizeId);
            return(View(product));
        }
        public ActionResult Sale()
        {
            List <Sale> sales = new List <Sale>();

            sales = (List <Sale>)Session["Sale"];

            Sale sale = new Sale();

            foreach (var item in sales)
            {
                db.Sales.Add(
                    new Sale()
                {
                    ProductId     = item.ProductId,
                    SaleDateTime  = item.SaleDateTime,
                    ItemTotal     = item.ItemTotal,
                    Vat           = item.Vat,
                    TotalAmoun    = item.TotalAmoun,
                    TransactionId = 3,
                    InvoiceNumber = item.InvoiceNumber
                }
                    );

                db.SaveChanges();
            }


            List <ProductSale> productSales = new List <ProductSale>();

            productSales = (List <ProductSale>)Session["ProductSale"];

            foreach (var item in productSales)
            {
                db.ProductSales.Add(
                    new ProductSale
                {
                    ProductId    = item.ProductId,
                    SaleId       = item.SaleId,
                    SaleQuantity = item.SaleQuantity,
                    SalePrice    = item.SalePrice,
                    TotalPrice   = item.TotalPrice
                });
                db.SaveChanges();


                db.Database.ExecuteSqlCommand("UPDATE [dbo].[Product] SET ProductQuantity = ProductQuantity-'" + item.SaleQuantity + "' WHERE ProductId = '" + item.ProductId + "'");
            }

            Session.Remove("Sale");
            Session.Remove("ProductSale");
            POS();
            return(View("POS"));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "AdjustmentId,AdjustmentReason,ProductId,AdjustedQuantity,AdjustedDateTime")]
                                   Adjustment adjustment)
        {
            if (ModelState.IsValid)
            {
                db.Adjustments.Add(adjustment);
                db.SaveChanges();
                db.Database.ExecuteSqlCommand("UPDATE [dbo].[Product] SET ProductQuantity = ProductQuantity-1 WHERE ProductId = '" + adjustment.ProductId + "'");
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductCode", adjustment.ProductId);
            return(View(adjustment));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "CategoryId,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", category.CategoryId);
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", category.CategoryId);
            return(View(category));
            //https://stackoverflow.com/questions/36258700/mvc5-validation-failed-for-one-or-more-entities-see-entityvalidationerrors-pr
        }
        public ActionResult Sale()
        {
            List <Sale> sales = new List <Sale>();

            sales = (List <Sale>)Session["OrderdProductList"];
            foreach (var item in sales)
            {
                db.Sales.Add(
                    new Sale()
                {
                    ProductId = item.ProductId,
                    //SaleProductName = item.SaleProductName,
                    //SaleDateTime = item.SaleDateTime,
                    //SalePrice = item.SalePrice,
                    //SaleQuantity = item.SaleQuantity,
                    //TotalPrice = item.TotalPrice,
                    TransactionId = 3
                }
                    );
                db.SaveChanges();
            }

            Session.Remove("OrderdProductList");
            POS();
            return(View("POS"));
        }
        public ActionResult AddNewCategory(string qty)
        {
            Category category = new Category();

            category.CategoryName = qty;
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", category.CategoryId);
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", category.CategoryId);
            return(View(category));
        }