예제 #1
0
        public int NewBill()
        {
            var bill = new tcBill();

            db.tcBills.Add(bill);
            db.SaveChanges();
            return(bill.Id);
        }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            tcBill bill = db.tcBills.Find(id);

            //first step = return the products stock
            foreach (var product in bill.tcProductSales)
            {
                UpdateProductStock(product.ProductId, product.Quantity);
            }
            //second step = delete all productSales, serviceSales, clientDetails
            var list = new List <tcProductSale>();

            foreach (var item in bill.tcProductSales)
            {
                list.Add(item);
            }
            for (int i = 0; i < list.Count; i++)
            {
                DeleteProductSale(list[i]);
            }

            var saleList = new List <tcServiceSale>();

            foreach (var sale in bill.tcServiceSales)
            {
                saleList.Add(sale);
            }
            for (int i = 0; i < saleList.Count; i++)
            {
                db.tcServiceSales.Remove(saleList[i]);
            }

            var detailList = new List <tcClientDetail>();

            foreach (var detail in bill.tcClientDetails)
            {
                detailList.Add(detail);
            }
            for (int i = 0; i < detailList.Count; i++)
            {
                db.tcClientDetails.Remove(detailList[i]);
            }

            //now delete the bill
            db.tcBills.Remove(bill);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: tcProductSales/Details/5
        public ActionResult Details(int?id)
        {
            if (IsAllowed() == false)
            {
                return(RedirectToAction("Index", "Login"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tcBill tcBill = db.tcBills.Find(id);

            if (tcBill == null)
            {
                return(HttpNotFound());
            }
            return(View(tcBill));
        }
예제 #4
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);
        }