Exemplo n.º 1
0
        public async Task <IHttpActionResult> DeleteBuySlipItem(int id)
        {
            BuySlipItem buySlipItem = await db.BuySlipItems.FindAsync(id);

            if (buySlipItem == null)
            {
                return(NotFound());
            }

            db.BuySlipItems.Remove(buySlipItem);

            var stockitem = db.StockItems.
                            Where(x => x.ProductId == buySlipItem.ProductId).
                            FirstOrDefault();

            stockitem.Quantity -= buySlipItem.Quantity;

            //BuySlipItme
            await db.SaveChangesAsync();

            db.Entry(stockitem).State = EntityState.Modified;
            //SockItme
            await db.SaveChangesAsync();

            return(Ok(buySlipItem));
        }
Exemplo n.º 2
0
        private async Task DoStockAsync(BuySlipItem buySlipItem)
        {
            db.BuySlipItems.Add(buySlipItem);
            await db.SaveChangesAsync();

            var stockItem = db.StockItems.Where(x => x.ProductId == buySlipItem.ProductId).
                            FirstOrDefault();

            if (stockItem != null)
            {
                stockItem.Quantity       += buySlipItem.Quantity;
                db.Entry(stockItem).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }
            else
            {
                StockItem st = new StockItem()
                {
                    ProductId = buySlipItem.ProductId,
                    Quantity  = buySlipItem.Quantity
                };
                db.StockItems.Add(st);
                await db.SaveChangesAsync();
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit([Bind(Include = "Id,Price,Quantity,Description,ProductId,RepositoryId,BuySlipId")] BuySlipItem buySlipItem)
        {
            if (ModelState.IsValid)
            {
                db.Entry(buySlipItem).State = EntityState.Modified;

                int dif = buySlipItem.Quantity - db.BuySlipItems.
                          Where(x => x.Id == buySlipItem.Id).
                          Select(x => x.Quantity).FirstOrDefault();

                db.SaveChanges();

                var stockitem = db.StockItems.
                                FirstOrDefault(x => x.ProductId == buySlipItem.ProductId);
                stockitem.Quantity       += dif;
                db.Entry(stockitem).State = EntityState.Modified;
                db.SaveChanges();
                TempData["message"] = "درخواست شما انجام شد";
                TempData["success"] = "true";
                return(Json(new { success = true }));
            }
            ViewBag.BuySlipId    = new SelectList(db.BuySlips, "Id", "DateCreation", buySlipItem.BuySlipId);
            ViewBag.ProductId    = new SelectList(db.Products, "Id", "Name", buySlipItem.ProductId);
            ViewBag.RepositoryId = new SelectList(db.Repositories, "Id", "Code", buySlipItem.RepositoryId);
            TempData["message"]  = "درخواست شما لغو شد";
            TempData["success"]  = "false";
            return(PartialView(viewName: "Edit", model: buySlipItem));
        }
Exemplo n.º 4
0
        public ActionResult CreatePop()
        {
            ViewBag.BuySlipId    = new SelectList(db.BuySlips, "Id", "DateCreation");
            ViewBag.ProductId    = new SelectList(db.Products, "Id", "Name");
            ViewBag.RepositoryId = new SelectList(db.Repositories, "Id", "Name");
            BuySlipItem bsItem = new BuySlipItem();

            return(PartialView(viewName: "_Create", model: bsItem));
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> GetBuySlipItem(int id)
        {
            BuySlipItem buySlipItem = await db.BuySlipItems.FindAsync(id);

            if (buySlipItem == null)
            {
                return(NotFound());
            }

            return(Ok(buySlipItem));
        }
Exemplo n.º 6
0
        // GET: BuySlipItems/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BuySlipItem buySlipItem = db.BuySlipItems.Find(id);

            if (buySlipItem == null)
            {
                return(HttpNotFound());
            }
            return(PartialView(viewName: "Details", model: buySlipItem));
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> PostBuySlipItem(BuySlipItem buySlipItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //db.BuySlipItems.Add(buySlipItem);
            //await db.SaveChangesAsync();
            #region Stock
            await DoStockAsync(buySlipItem);

            #endregion

            return(CreatedAtRoute("DefaultApi", new { id = buySlipItem.Id }, buySlipItem));
        }
Exemplo n.º 8
0
        // GET: BuySlipItems/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BuySlipItem buySlipItem = db.BuySlipItems.Find(id);

            if (buySlipItem == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BuySlipId    = new SelectList(db.BuySlips, "Id", "DateCreation", buySlipItem.BuySlipId);
            ViewBag.ProductId    = new SelectList(db.Products, "Id", "Name", buySlipItem.ProductId);
            ViewBag.RepositoryId = new SelectList(db.Repositories, "Id", "Code", buySlipItem.RepositoryId);
            return(PartialView(viewName: "Edit", model: buySlipItem));
        }
Exemplo n.º 9
0
        public async Task <IHttpActionResult> PutBuySlipItem(int id, BuySlipItem buySlipItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != buySlipItem.Id)
            {
                return(BadRequest());
            }

            db.Entry(buySlipItem).State = EntityState.Modified;

            int dif = buySlipItem.Quantity - db.BuySlipItems.
                      Where(x => x.Id == buySlipItem.Id).
                      Select(x => x.Quantity).FirstOrDefault();

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BuySlipItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            var stockitem = db.StockItems.
                            FirstOrDefault(x => x.ProductId == buySlipItem.ProductId);

            stockitem.Quantity       += dif;
            db.Entry(stockitem).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 10
0
        public ActionResult DeleteConfirmed(int id)
        {
            BuySlipItem buySlipItem = db.BuySlipItems.Find(id);

            db.BuySlipItems.Remove(buySlipItem);

            var stockitem = db.StockItems.
                            Where(x => x.ProductId == buySlipItem.ProductId).
                            FirstOrDefault();

            stockitem.Quantity -= buySlipItem.Quantity;
            db.SaveChanges();

            db.Entry(stockitem).State = EntityState.Modified;
            db.SaveChanges();
            TempData["message"] = "درخواست شما انجام شد";
            TempData["success"] = "true";
            return(Json(new { success = true }));
        }
Exemplo n.º 11
0
        public ActionResult CreatePop([Bind(Include = "Id,Price,Quantity,Description,ProductId,RepositoryId")] BuySlipItem buySlipItem,
                                      FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                GetBuySlipId();
                buySlipItem.BuySlipId = int.Parse(Session["BuySlipId"].ToString());

                DoStock(buySlipItem);
                TempData["message"] = "درخواست شما انجام شد";
                TempData["success"] = "true";
                return(Json(new { success = true }));
            }

            ViewBag.BuySlipId    = new SelectList(db.BuySlips, "Id", "DateCreation", buySlipItem.BuySlipId);
            ViewBag.ProductId    = new SelectList(db.Products, "Id", "Name", buySlipItem.ProductId);
            ViewBag.RepositoryId = new SelectList(db.Repositories, "Id", "Name", buySlipItem.RepositoryId);
            TempData["message"]  = "درخواست شما انجام شد";
            TempData["success"]  = "true";
            return(PartialView(viewName: "_Create", model: buySlipItem));
        }
Exemplo n.º 12
0
        public ActionResult Create([Bind(Include = "Id,Price,Quantity,Description,ProductId,RepositoryId")] BuySlipItem buySlipItem,
                                   FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                GetBuySlipId();
                buySlipItem.BuySlipId = int.Parse(Session["BuySlipId"].ToString());

                DoStock(buySlipItem);
                TempData["message"] = "درخواست شما انجام شد";
                TempData["success"] = "true";

                return(RedirectToAction("Edit", controllerName: "BuySlips",
                                        routeValues: new { Id = int.Parse(Session["BuySlipId"].ToString()) }));
            }

            ViewBag.BuySlipId    = new SelectList(db.BuySlips, "Id", "DateCreation", buySlipItem.BuySlipId);
            ViewBag.ProductId    = new SelectList(db.Products, "Id", "Name", buySlipItem.ProductId);
            ViewBag.RepositoryId = new SelectList(db.Repositories, "Id", "Name", buySlipItem.RepositoryId);
            TempData["message"]  = "درخواست شما لغو شد";
            TempData["success"]  = "false";
            return(View(buySlipItem));
        }