public ActionResult DeleteConfirmed(int id)
        {
            tcProductSale tcProductSale = db.tcProductSales.Find(id);

            db.tcProductSales.Remove(tcProductSale);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,ProductId,Quantity,Price,BillId")] tcProductSale tcProductSale)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tcProductSale).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BillId    = new SelectList(db.tcBills, "Id", "ClientId", tcProductSale.BillId);
     ViewBag.ProductId = new SelectList(db.tcProducts, "Id", "Name", tcProductSale.ProductId);
     return(View(tcProductSale));
 }
        // GET: tcProductSales/Delete/5
        public ActionResult Delete(int?id)
        {
            if (IsAllowed() == false)
            {
                return(RedirectToAction("Index", "Login"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tcProductSale tcProductSale = db.tcProductSales.Find(id);

            if (tcProductSale == null)
            {
                return(HttpNotFound());
            }
            return(View(tcProductSale));
        }
        // GET: tcProductSales/Edit/5
        public ActionResult Edit(int?id)
        {
            if (IsAllowed() == false)
            {
                return(RedirectToAction("Index", "Login"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tcProductSale tcProductSale = db.tcProductSales.Find(id);

            if (tcProductSale == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BillId    = new SelectList(db.tcBills, "Id", "ClientId", tcProductSale.BillId);
            ViewBag.ProductId = new SelectList(db.tcProducts, "Id", "Name", tcProductSale.ProductId);
            return(View(tcProductSale));
        }
Ejemplo n.º 5
0
        public string PostSale(string sale)
        {
            var billId = NewBill();
            var lines  = sale.Split('!');

            foreach (var item in lines)
            {
                var fields = item.Split(',');
                var sl     = new tcProductSale()
                {
                    ProductId = int.Parse(fields[0]),
                    Quantity  = int.Parse(fields[1]),
                    Price     = Convert.ToDecimal(fields[2]),
                    BillId    = billId
                };
                db.tcProductSales.Add(sl);
                var product = db.tcProducts.Find(sl.ProductId);
                product.Stock           = product.Stock - sl.Quantity;
                db.Entry(product).State = EntityState.Modified;
            }
            db.SaveChanges();
            return(billId.ToString());
        }
Ejemplo n.º 6
0
 void DeleteProductSale(tcProductSale item)
 {
     db.tcProductSales.Remove(item);
 }
Ejemplo n.º 7
0
        public tcBill GetBillDetails(int id)
        {
            var bill = db.tcBills.Find(id);

            var products = new List <tcProductSale>();

            foreach (var item in bill.tcProductSales)
            {
                var p = new tcProductSale()
                {
                    Id = item.Id, BillId = item.Id, Price = item.Price, ProductId = item.ProductId, Quantity = item.Quantity, tcProduct = new tcProduct()
                    {
                        Name = item.tcProduct.Name
                    }
                };
                products.Add(p);
            }

            var services = new List <tcServiceSale>();

            foreach (var item in bill.tcServiceSales)
            {
                var s = new tcServiceSale()
                {
                    Id = item.Id, BillId = item.BillId, Price = item.Price, Quantity = item.Quantity, ServiceId = item.ServiceId, tcService = new tcService()
                    {
                        Name = item.tcService.Name
                    }
                };
                services.Add(s);
            }

            var payments = new List <tcClientDetail>();

            foreach (var item in bill.tcClientDetails)
            {
                var p = new tcClientDetail()
                {
                    BillId        = item.BillId,
                    ClientId      = item.ClientId,
                    Id            = item.Id,
                    Credit        = item.Credit,
                    Payment       = item.Payment,
                    PaymentMethod = item.PaymentMethod
                };
                payments.Add(p);
            }

            var result = new tcBill()
            {
                Id       = bill.Id,
                ClientId = bill.ClientId,
                tcClient = new tcClient()
                {
                    Id = bill.ClientId, Name = bill.tcClient.Name, Group = bill.tcClient.Group
                },
                IsCredit        = bill.IsCredit,
                PaymentMethod   = bill.PaymentMethod,
                User            = bill.User,
                tcProductSales  = products,
                tcServiceSales  = services,
                tcClientDetails = payments
            };

            return(result);
        }