Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Cust_Acount cust_Acount = db.cust_Acounts.Find(id);

            db.cust_Acounts.Remove(cust_Acount);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Id,CUST_TBLId,SalNo,RslNo,Amount,EslNo,Date")] Cust_Acount cust_Acount)
 {
     if (ModelState.IsValid)
     {
         cust_Acount.EslNo           = cust_Acount.EslNo;
         db.Entry(cust_Acount).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CUST_TBLId = new SelectList(db.CUST_TBLs, "Id", "CUST_NAME", cust_Acount.CUST_TBLId);
     return(View(cust_Acount));
 }
Ejemplo n.º 3
0
        // GET: Cust_Acount/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cust_Acount cust_Acount = db.cust_Acounts.Find(id);

            if (cust_Acount == null)
            {
                return(HttpNotFound());
            }
            return(View(cust_Acount));
        }
Ejemplo n.º 4
0
        // GET: Cust_Acount/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cust_Acount cust_Acount = db.cust_Acounts.Find(id);

            if (cust_Acount == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CUST_TBLId = new SelectList(db.CUST_TBLs, "Id", "CUST_NAME", cust_Acount.CUST_TBLId);
            return(View(cust_Acount));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Id,CUST_TBLId,Amount,Date")] Cust_Acount cust_Acount)
        {
            if (ModelState.IsValid)
            {
                cust_Acount.RslNo  = 0;
                cust_Acount.RslNo  = 0;
                cust_Acount.Date   = DateTime.Now.Date;
                cust_Acount.EslNo  = Convert.ToInt32(db.cust_Acounts.Max(c => c.EslNo + 1));
                cust_Acount.Amount = -cust_Acount.Amount;
                db.cust_Acounts.Add(cust_Acount);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CUST_TBLId = new SelectList(db.CUST_TBLs, "Id", "CUST_NAME", cust_Acount.CUST_TBLId);
            return(View(cust_Acount));
        }
Ejemplo n.º 6
0
        public JsonResult AddOrderAndOrderDetials(OrderViewModel orderViewModel)
        {
            bool status = true;

            var isValidModel = TryUpdateModel(orderViewModel);

            if (isValidModel)
            {
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    var     cusname = db.CUST_TBLs.Find(orderViewModel.Cust_TBLId);
                    Sal_tbl order   = new Sal_tbl()
                    {
                        OrderDate = System.DateTime.Now,
                        Cust_Id   = orderViewModel.Cust_TBLId,
                        Cust_Name = cusname.CUST_NAME
                    };
                    db.Sal_Tbls.Add(order);

                    if (db.SaveChanges() > 0)
                    {
                        int orderID = db.Sal_Tbls.Max(o => o.Id);

                        foreach (var item in orderViewModel.Items)
                        {
                            SaleDetails orderDetails = new SaleDetails()
                            {
                                Sal_TblId      = orderID,
                                Product_TbleId = item.ProductID,
                                Price          = item.Price,
                                QtyOut         = item.Quantity,
                                QtyIn          = 0,
                                Amount         = item.TotalPrice
                            };
                            Stock stock = new Stock()
                            {
                                Prod_Id = item.ProductID,
                                StQty   = -item.Quantity,
                                Case    = "مبيعات",
                                Date    = System.DateTime.Now,
                                MndId   = cusname.MND_TBLId,
                                Cust_Id = orderViewModel.Cust_TBLId
                            };
                            Cust_Acount cust = new Cust_Acount()
                            {
                                CUST_TBLId = orderViewModel.Cust_TBLId,
                                SalNo      = orderID,
                                RslNo      = 0,
                                EslNo      = 0,
                                Amount     = item.TotalPrice,
                                Date       = System.DateTime.Now
                            };


                            db.SaleDetails.Add(orderDetails);
                            db.stocks.Add(stock);
                            db.cust_Acounts.Add(cust);
                        }

                        if (db.SaveChanges() > 0)
                        {
                            return(new JsonResult {
                                Data = new { status = status, message = "Order Added Successfully" }
                            });
                        }
                    }
                }
            }

            status = false;
            return(new JsonResult {
                Data = new { status = status, message = "Error !" }
            });
        }