public ActionResult DeleteConfirmed(int id)
        {
            WarehouseProducts warehouseproducts = db.WarehouseProducts.Find(id);

            db.WarehouseProducts.Remove(warehouseproducts);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public void TransferProduct(string userId, int productId, ApiProdTransfer info)
        {
            using var context = _di.GetService <ApplicationDbContext>();
            var from = getStockAndVerify(productId, info, context);

            using var transaction = context.Database.BeginTransaction();
            try
            {
                var to = context.WarehouseProducts.FirstOrDefault(it => it.ProductId == productId && it.WarehouseId == info.ToId);
                if (to == null)
                {
                    to = new WarehouseProducts()
                    {
                        ProductId = productId, WarehouseId = info.ToId, Quantity = 0
                    };
                    context.WarehouseProducts.Add(to);
                }

                to.Quantity += info.Quantity;
                context.SaveChanges();

                var date = DateTime.UtcNow;
                context.ProductsTrqansactions.Add(new ProductAction
                {
                    ProductId   = productId,
                    Quantity    = -info.Quantity,
                    WarehouseId = info.FromId,
                    UserId      = userId,
                    Date        = date,
                    Description = $"Переміщення товару зі складу {info.FromId} на склад {info.ToId} (Зменшення)",
                    Operation   = OperationDescription.TransferRemove,
                    Price       = 0,
                });
                context.SaveChanges();

                context.ProductsTrqansactions.Add(new ProductAction()
                {
                    ProductId   = productId,
                    Quantity    = info.Quantity,
                    WarehouseId = info.ToId,
                    UserId      = userId,
                    Date        = date,
                    Description = $"Переміщення товару зі складу {info.FromId} на склад {info.ToId} (Збільшення)",
                    Operation   = OperationDescription.TransferAdd,
                    Price       = 0,
                });
                context.SaveChanges();

                // Commit transaction if all commands succeed, transaction will auto-rollback
                // when disposed if either commands fails
                transaction.Commit();
            }
            catch (Exception ex)
            {
                // TODO: Handle failure
                throw ex;
            }
        }
        //
        // GET: /WarehouseProducts/Details/5

        public ActionResult Details(int id = 0)
        {
            WarehouseProducts warehouseproducts = db.WarehouseProducts.Find(id);

            if (warehouseproducts == null)
            {
                return(HttpNotFound());
            }
            return(View(warehouseproducts));
        }
 public ActionResult Edit(WarehouseProducts warehouseproducts)
 {
     if (ModelState.IsValid)
     {
         db.Entry(warehouseproducts).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.idProducts  = new SelectList(db.Products, "id", "name", warehouseproducts.idProducts);
     ViewBag.idWarehouse = new SelectList(db.Warehouse, "id", "description", warehouseproducts.idWarehouse);
     return(View(warehouseproducts));
 }
        //
        // GET: /WarehouseProducts/Edit/5

        public ActionResult Edit(int id = 0)
        {
            WarehouseProducts warehouseproducts = db.WarehouseProducts.Find(id);

            if (warehouseproducts == null)
            {
                return(HttpNotFound());
            }
            ViewBag.idProducts  = new SelectList(db.Products, "id", "name", warehouseproducts.idProducts);
            ViewBag.idWarehouse = new SelectList(db.Warehouse, "id", "description", warehouseproducts.idWarehouse);
            return(View(warehouseproducts));
        }
        public ActionResult Create(WarehouseProducts warehouseproducts)
        {
            if (ModelState.IsValid)
            {
                db.WarehouseProducts.Add(warehouseproducts);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Product = new SelectList(db.Products, "Id", "Name", warehouseproducts.Product);
            ViewBag.Warehouse = new SelectList(db.Warehouse, "Id", "Description", warehouseproducts.Warehouse);
            return View(warehouseproducts);
        }
Beispiel #7
0
        public void AddProduct(string userId, int productId, ApiProdAction info)
        {
            using var context = _di.GetService <ApplicationDbContext>();
            var from = context.WarehouseProducts.FirstOrDefault(it => it.ProductId == productId && it.WarehouseId == info.FromId);

            if (@from == null)
            {
                @from = new WarehouseProducts()
                {
                    ProductId = productId, WarehouseId = info.FromId, Quantity = 0
                };
                context.WarehouseProducts.Add(@from);
            }
            @from.Quantity += info.Quantity;

            using var transaction = context.Database.BeginTransaction();
            try
            {
                context.SaveChanges();

                var date = DateTime.UtcNow;
                context.ProductsTrqansactions.Add(new ProductAction()
                {
                    ProductId   = productId,
                    Quantity    = info.Quantity,
                    WarehouseId = info.FromId,
                    UserId      = userId,
                    Date        = date,
                    Description = $"Товар додано адміністратором",
                    Operation   = OperationDescription.StockRenew,
                    Price       = 0,
                });
                context.SaveChanges();

                // Commit transaction if all commands succeed, transaction will auto-rollback
                // when disposed if either commands fails
                transaction.Commit();
            }
            catch (Exception ex)
            {
                // TODO: Handle failure
                throw ex;
            }
        }
Beispiel #8
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                CheckWarehouseRequest parm = new CheckWarehouseRequest();
                using (StreamReader sr = new StreamReader(context.Request.InputStream))
                {
                    String data = sr.ReadToEnd();
                    parm = new JavaScriptSerializer().Deserialize <CheckWarehouseRequest>(data);
                }

                CheckWarehouseResponse ap = new CheckWarehouseResponse();
                using (DLSMEntities db = new DLSMEntities())
                {
                    using (var dbContextTransaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            var result = db.sp_ApiCheckWarehouse(Convert.ToInt32(parm.WH_ID)).ToList();
                            if (result.Count() > 0)
                            {
                                ap.resultcode      = "1";
                                ap.WH_ID           = parm.WH_ID;
                                ap.WhName          = "" + result[0].WhName;
                                ap.update_datetime = DateTime.Now.ToString();

                                ap.product_remain = new WarehouseProducts[result.Count()];
                                int e = 0;
                                foreach (var i in result)
                                {
                                    WarehouseProducts a = new WarehouseProducts();
                                    a.product_name = i.PdName;
                                    a.curr_qty     = "" + i.Qty;
                                    a.min_qty      = "" + i.MinStock;

                                    ap.product_remain[e++] = a;
                                }
                                ap.message = "OK";
                            }
                            else
                            {
                                dbContextTransaction.Rollback();
                                ap.resultcode = "0";
                                ap.message    = "not found";
                            }
                        }
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                            ap.resultcode = "0";
                            ap.message    = ex.InnerException == null ? (ex.Message == null ? "Error: CheckWarehouse catch 2" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace;
                        }
                    }
                }
                string json = new JavaScriptSerializer().Serialize(ap);

                context.Response.ContentType = "text/javascript";
                context.Response.Write(json);
            }
            catch (Exception ex)
            {
                CheckWarehouseResponse ap = new CheckWarehouseResponse();
                ap.resultcode = "0";
                ap.message    = ex.InnerException == null ? (ex.Message == null ? "Error: CheckWarehouse catch 1" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace;


                string json = new JavaScriptSerializer().Serialize(ap);
                context.Response.ContentType = "text/javascript";
                context.Response.Write(json);
            }
        }