private async Task <Tbl_Invoices> AddProductsToInvoice(List <ProductDto> products) { Tbl_Invoices tbl_Invoice = new Tbl_Invoices(); List <Tbl_InvoiceItems> invoiceItems = new List <Tbl_InvoiceItems>(); foreach (var item in products) { var getProduct = await _productService.GetProductByIdAsync(item.productsId); if (getProduct != null) { var temp = new Tbl_InvoiceItems(); temp.quantity = item.quantity; temp.unitPrice = getProduct.amount; if (getProduct.category.ToLower() == "grocery") { temp.isGrocery = true; } temp.products = getProduct; temp.productsId = getProduct.id; tbl_Invoice.totalProductsAmount += (temp.quantity * temp.unitPrice); invoiceItems.Add(temp); } } tbl_Invoice.innvoiceItems = invoiceItems; tbl_Invoice.totalAmount = tbl_Invoice.totalProductsAmount; return(tbl_Invoice); }
public JsonResult InsertInvoicePurchase(string UserBizCode, string TotalPrice) { var DbUser = _context.Tbl_User.SingleOrDefault(u => u.BIZCode == UserBizCode); PersianDateTime now = PersianDateTime.Now; var ShamsiDate = now.ToString(); DateTime MiladiDate = DateTime.Now; var Invoice = new Tbl_Invoices { UserID = DbUser.Id, SellerID = Convert.ToInt32(Session["UserId"]), DateTime = ShamsiDate, InvoiceStatesID = 1, Description = "خرید از فروشگاه سیرجان" }; var Purchase = new Tbl_SirjanPurchase { UserId = DbUser.Id, PurchaseId = 1, Price = TotalPrice, DateTime = ShamsiDate, MiladiDate = MiladiDate, Description = "خرید از فروشگاه سیرجان" }; _context.Tbl_Invoices.Add(Invoice); _context.SaveChanges(); _context.Tbl_SirjanPurchase.Add(Purchase); _context.SaveChanges(); int LastInvoiceId = _context.Database.SqlQuery <int>(@"select top 1 Id from Tbl_Invoices order by Id desc").FirstOrDefault <int>(); return(Json(LastInvoiceId.ToString(), JsonRequestBehavior.AllowGet)); }
public JsonResult InsertInvoice() { PersianDateTime now = PersianDateTime.Now; var DateTime = now.ToString(); var Invoice = new Tbl_Invoices { UserID = 1007, SellerID = 1008, DateTime = DateTime, InvoiceStatesID = 1, Description = "خرید از فروشگاه تهران" }; _context.Tbl_Invoices.Add(Invoice); _context.SaveChanges(); int LastInvoiceId = _context.Database.SqlQuery <int>(@"select top 1 Id from Tbl_Invoices order by Id desc").FirstOrDefault <int>(); return(Json(LastInvoiceId, JsonRequestBehavior.AllowGet)); }