Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "ProductID,ProductCode,ProductName,SupplierID,Price,Notes")] Product product)
        {
            if (ModelState.IsValid)
            {
                product.KursID          = db.KursSG.Where(o => o.Currency == "SGD").Select(o => o.KursID).FirstOrDefault();
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();

                Logger.AddLog(
                    User.Identity.Name,
                    product.ProductID,
                    Logger.Product,
                    Logger.Edit,
                    Logger.DescriptionProduct(product.ProductCode, product.ProductName, product.KursID, product.Price)
                    );

                return(RedirectToAction("Index"));
            }
            var selectrate = (from b in db.KursSG
                              select new { b.Rate, text = b.Currency + "-" + b.Rate });

            ViewBag.Kurs       = new SelectList(selectrate.ToList(), "Rate", "text", product.KursID);
            ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", product.SupplierID);
            return(View(product));
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "KursID,Currency,Rate")] Kurs kurs)
 {
     if (ModelState.IsValid)
     {
         db.Entry(kurs).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(kurs));
 }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "SupplierID,SupplierName,Notes")] Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplier));
 }
Ejemplo n.º 4
0
        public ActionResult Edit([Bind(Include = "ProductOutID,ProductCode,Qty,Notes")] ProductOut productOut)
        {
            if (ModelState.IsValid)
            {
                ProductOut obj = db.ProductsOut.Find(productOut.ProductOutID);

                int qtyBefore = obj.Qty;

                obj.Qty         = productOut.Qty;
                obj.ProductCode = productOut.ProductCode;
                obj.Notes       = productOut.Notes;

                DateTime date     = Date.getDate();
                DateTime fromDate = new DateTime(2014, 01, 01);

                string query = string.Format("EXEC [dbo].[sp_GetReportStock] @dateFrom = '{0}', @dateTo = '{1}'", fromDate.ToString("yyyy-MM-dd"), date.ToString("yyyy-MM-dd"));
                IEnumerable <ReportStock> list = db.Database.SqlQuery <ReportStock>(query);

                int stock = list.Where(o => o.ProductCode == productOut.ProductCode).FirstOrDefault().Stock + qtyBefore;

                var oldobj      = db.ProductsOut.Find(productOut.ProductOutID);
                var productName = db.Products.Where(o => o.ProductCode == productOut.ProductCode).FirstOrDefault().ProductName;

                if (productOut.Qty <= stock)
                {
                    db.Entry(obj).State = EntityState.Modified;
                    db.SaveChanges();

                    Logger.AddLog(
                        User.Identity.Name,
                        productOut.ProductOutID,
                        Logger.ProductOut,
                        Logger.Edit,
                        Logger.DescriptionQty(productOut.ProductCode, productName, productOut.Qty, qtyBefore)
                        );

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.msg = "Quantity can't be greater than stock (" + stock.ToString() + ")";
                }
            }

            IEnumerable <Product> listProduct = db.Products;

            foreach (var item in listProduct)
            {
                item.ProductName = item.ProductCode + " - " + item.ProductName;
            }

            ViewBag.ProductCode = new SelectList(listProduct, "ProductCode", "ProductName", productOut.ProductCode);
            return(View(productOut));
        }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "ProductInID,ProductCode,Qty,Price,Notes")] ProductIn productIn)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productIn).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductID = new SelectList(db.Products, "ProductCode", "ProductCode", productIn.ProductCode);
     return(View(productIn));
 }
Ejemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "SaleID,ProductCode,Qty,Notes")] Sale sale)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sale).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductCode = new SelectList(db.Products, "ProductCode", "ProductCode", sale.ProductCode);
     return(View(sale));
 }
Ejemplo n.º 7
0
        public ActionResult Edit([Bind(Include = "KursID,Currency,Rate")] Kurs kurs)
        {
            if (ModelState.IsValid)
            {
                db.Entry(kurs).State = EntityState.Modified;
                db.SaveChanges();

                Logger.AddLog(
                     User.Identity.Name,
                     kurs.KursID,
                     Logger.Rate,
                     Logger.Edit,
                     Logger.DescriptionRate(kurs.Currency, kurs.Rate)
                 );

                return RedirectToAction("Index");
            }
            return View(kurs);
        }
Ejemplo n.º 8
0
        public ActionResult Edit([Bind(Include = "ProductInID,ProductCode,Qty,Notes")] ProductIn productIn)
        {
            if (ModelState.IsValid)
            {
                ProductIn obj = db.ProducsIn.Find(productIn.ProductInID);

                int qtyBefore   = obj.Qty;
                int priceBefore = obj.Price;

                obj.Qty = productIn.Qty;

                var price = db.Products.Where(o => o.ProductCode == productIn.ProductCode).Select(o => o.Price).FirstOrDefault();
                obj.Price = productIn.Qty * price;

                obj.ProductCode = productIn.ProductCode;
                obj.Notes       = productIn.Notes;

                var oldobj      = db.ProducsIn.Find(productIn.ProductInID);
                var productName = db.Products.Where(o => o.ProductCode == productIn.ProductCode).FirstOrDefault().ProductName;

                db.Entry(obj).State = EntityState.Modified;
                db.SaveChanges();

                Logger.AddLog(
                    User.Identity.Name,
                    productIn.ProductInID,
                    Logger.ProductIn,
                    Logger.Edit,
                    Logger.DescriptionQtyPrice(productIn.ProductCode, productName, productIn.Qty, qtyBefore, productIn.Price, priceBefore)
                    );

                return(RedirectToAction("Index"));
            }
            ViewBag.ProductID = new SelectList(db.Products, "ProductCode", "ProductCode", productIn.ProductCode);
            return(View(productIn));
        }