public async Task <IActionResult> PutBillProduct(int id, BillProduct billProduct) { if (id != billProduct.Id) { return(BadRequest()); } _context.Entry(billProduct).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BillProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// Thêm hóa đơn private void btnSave_Click(object sender, EventArgs e) { if (txtCustomerId.Text == "") { txtCustomerId.Text = AddBillBLL.NextId("KH", bll.GetLastCustomer(), 2); } List <BillProduct> proList = new List <BillProduct>(); foreach (DataGridViewRow row in dgvProductAdded.Rows) { BillProduct bp = new BillProduct(); bp.proId = row.Cells[0].Value.ToString(); bp.num = int.Parse(row.Cells[2].Value.ToString()); proList.Add(bp); } //chú ý !!!!!!!!!!!!!!!!! chổ này chưa lấy được mã nhân viên bll.SaveBill(txtCustomerId.Text, "NV1", int.Parse(txtSumMoney.Text), proList); txtCustomerName.Text = ""; txtCustomerId.Text = ""; txtPhoneNumber.Text = ""; txtAddress.Text = ""; txtIdCardNumber.Text = ""; txtPrice.Text = ""; dgvProductAdded.Rows.Clear(); lbStatus.Text = "Lưu thành công"; lbStatus.ForeColor = Color.Green; }
private void addProductToTable(BillProduct billProd) { var billProduct = billProd; if (billProduct != null) { var product = EntityManager.GetProduct(billProduct.ProductId); productsTable.Rows.Add(product.Id, product.Tu, product.Measure, product.Name, billProduct.Quantity, billProduct.Price, billProduct.Nds, billProduct.Sum); } }
public IActionResult AddBillProduct(BillProduct billProductToAdd) { var wasAddSuccessful = _billProductRepository.AddBillProduct(billProductToAdd); if (wasAddSuccessful) { return(Ok()); } return(Forbid()); }
private void okButton_Click(object sender, EventArgs e) { BillProduct = new BillProduct() { ProductId = GetSelectedIdFromTable(productTable), Quantity = (int)quantityNumeric.Value, Price = (double)priceNumeric.Value, Nds = (int)ndsNumeric.Value }; BillProduct.Sum = BillProduct.Price * BillProduct.Quantity; DialogResult = DialogResult.OK; Close(); }
public bool AddBillProduct(BillProduct billProductToAdd) { var doesProductExist = _context.Products.Any(product => product.Id.Equals(billProductToAdd.ProductId)); if (!doesProductExist) { return(false); } _context.BillProducts.Add(billProductToAdd); //_context.SaveChanges(); return(true); }
public static void InsertBillProduct(BillProduct billProduct) { var query = @"INSERT INTO Bill_Product VALUES (@billId, @productId, @quantity, @price, @nds, @sum);"; var command = new SQLiteCommand(query, _connection); command.Parameters.AddWithValue("@billId", billProduct.BillId); command.Parameters.AddWithValue("@productId", billProduct.ProductId); command.Parameters.AddWithValue("@quantity", billProduct.Quantity); command.Parameters.AddWithValue("@price", billProduct.Price); command.Parameters.AddWithValue("@nds", billProduct.Nds); command.Parameters.AddWithValue("@sum", billProduct.Sum); command.ExecuteNonQuery(); }
public static void UpdateBillProduct(long billId, long productId, BillProduct billProduct) { var query = @"UPDATE Bill_Product SET Quantity = @quantity, Price = @price, Nds = @nds, Sum = @sum WHERE Bill_Id = @billId AND Product_Id = @productId;"; var command = new SQLiteCommand(query, _connection); command.Parameters.AddWithValue("@billId", billProduct.BillId); command.Parameters.AddWithValue("@productId", billProduct.ProductId); command.Parameters.AddWithValue("@quantity", billProduct.Quantity); command.Parameters.AddWithValue("@price", billProduct.Price); command.Parameters.AddWithValue("@nds", billProduct.Nds); command.Parameters.AddWithValue("@sum", billProduct.Sum); command.ExecuteNonQuery(); }
public async Task <ActionResult <BillProduct> > PostBillProduct(BillProduct billProduct) { if (billProduct.ProductId == 0) { billProduct.ProductId = billProduct.Product.ProductId; billProduct.Product = null; } _context.BillProducts.Add(billProduct); await _context.SaveChangesAsync(); var bill = _context.Bills.Find(billProduct.BillId); billProduct.Bill.Total += billProduct.Amount * _context.Products.Find(billProduct.ProductId).BasePrice; _context.Entry(bill).State = EntityState.Detached; _context.Entry(billProduct.Bill).State = EntityState.Modified; _context.SaveChanges(); return(CreatedAtAction("GetBillProduct", new { id = billProduct.BillId }, billProduct)); }
public static BillProduct GetBillProduct(long billId, long productId) { var qery = @"SELECT * FROM Product WHERE Bill_Id = @billId AND Product_Id = @productId;"; var command = new SQLiteCommand(qery, _connection); command.Parameters.AddWithValue("@billId", billId); command.Parameters.AddWithValue("@productId", productId); var reader = command.ExecuteReader(); reader.Read(); var billProduct = new BillProduct() { BillId = reader.GetInt64(0), ProductId = reader.GetInt64(1), Quantity = reader.GetInt32(2), Price = reader.GetInt32(3), Nds = reader.GetInt32(4), Sum = reader.GetInt32(5), }; return(billProduct); }
public IActionResult CheckOut(Bill billVM) { var cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); var userTmp = _userProfileDatabase.Find(s => s.UserName == User.Identity.Name).FirstOrDefault(); //Count Discount int discount = 0; if (userTmp.Score >= 10 && userTmp.Score < 30) { discount = 10; } else if (userTmp.Score >= 30 && userTmp.Score < 50) { discount = 20; } else if (userTmp.Score >= 50) { discount = 30; } //Create Bill var total = cart.Sum(item => item.Product.Price * item.Quantity); var orderTotal = total - ((total * discount) / 100); billVM.UserId = userTmp.UserID; billVM.CreatedDate = DateTime.Now; billVM.Discount = discount; billVM.TotalPrice = total; billVM.OrderTotal = orderTotal; billVM.State = 1; //Bill bill = new Bill //{ // UserId = userTmp.UserID, // CreatedDate = DateTime.Now, // Discount = discount, // TotalPrice = total, // OrderTotal = orderTotal, // State = 1 //}; _billDatabase.Create(billVM); //Create BillProduct int billId = _database.Bills.Max(m => m.BillID); foreach (var item in cart) { BillProduct billPro = new BillProduct { BillID = billId, ProductID = item.Product.ProductID, Quantity = item.Quantity, Total = item.Quantity * item.Product.Price }; _billProductDatabase.Create(billPro); } //Remove Cart List <Item> removeCart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart"); removeCart = null; SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", removeCart); //Sending Email //using (var message = new MailMessage()) //{ // message.To.Add(new MailAddress("*****@*****.**", "To Name")); // message.From = new MailAddress("*****@*****.**", "From Name"); // message.CC.Add(new MailAddress("*****@*****.**", "CC Name")); // message.Bcc.Add(new MailAddress("*****@*****.**", "BCC Name")); // message.Subject = "Subject"; // message.Body = "Body"; // message.IsBodyHtml = true; //} //using (var client = new SmtpClient("smtp.gmail.com")) //{ // client.Port = 587; // client.Credentials = new NetworkCredential("*****@*****.**", "password"); // client.EnableSsl = true; // client.Send(message); //} return(RedirectToAction("ProductView", "Product")); }
public IActionResult Index(int shippingID, int phone, string addressDetails, int paymentID, float tempTotal, float total) { //POST//Address => Payment => Bill => BillProduct string userID = _userManager.GetUserId(User); #region Address Address address = new Address() { shippingID = shippingID, addressDetails = addressDetails, addressPhone = phone }; string _address = JsonConvert.SerializeObject(address); StringContent request = new StringContent(_address, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync($"http://shirleyomda-001-site1.etempurl.com/odata/Addresses", request).Result; var myAddress = response.Content.ReadAsStringAsync().Result; RootObject addressRoot = JsonConvert.DeserializeObject <RootObject>(myAddress); int addressID = addressRoot.addressID; #endregion #region Bill Bill bill = new Bill() { paymentID = paymentID, billTotal = total, billSubTotal = tempTotal, billDate = DateTime.Parse(DateTime.Now.ToShortDateString()), userID = userID, addressID = addressID }; string _bill = JsonConvert.SerializeObject(bill); StringContent request2 = new StringContent(_bill, Encoding.UTF8, "application/json"); HttpResponseMessage response2 = client.PostAsync($"http://shirleyomda-001-site1.etempurl.com/odata/Bills", request2).Result; var myBill = response2.Content.ReadAsStringAsync().Result; RootObject billRoot = JsonConvert.DeserializeObject <RootObject>(myBill); int billID = billRoot.billID; #endregion #region BillProduct //StoreID To get all carts Products(For BillProduct) //foreach to post billProduct HttpResponseMessage response4 = client.GetAsync($"http://shirleyomda-001-site1.etempurl.com/odata/Carts?$expand=Store/Product&$filter=userID eq '{userID}'").Result; string carts = response4.Content.ReadAsStringAsync().Result; RootObject cartList = JsonConvert.DeserializeObject <RootObject>(carts); List <Cart> myCarts = cartList.Value; foreach (var item in myCarts) { BillProduct billProduct = new BillProduct() { billID = billID, storeID = item.storeID, productID = item.Store.productID, billProductQuantity = item.quantity, billProductPrice = (item.Store.Product.productPrice) * (1 - item.Store.Product.productDiscount / 100) }; string _billProduct = JsonConvert.SerializeObject(billProduct); StringContent request3 = new StringContent(_billProduct, Encoding.UTF8, "application/json"); HttpResponseMessage response3 = client.PostAsync($"http://shirleyomda-001-site1.etempurl.com/odata/BillProducts", request3).Result; HttpResponseMessage response5 = client.DeleteAsync($"http://shirleyomda-001-site1.etempurl.com/odata/Carts({item.cartID})").Result; #region Modifying store quantity after purchasing int removedQuantity = item.quantity ?? 0; int storeQuantity = item.Store.productQuantity ?? 0; storeQuantity -= removedQuantity; string _storeQuantityUpdate = JsonConvert.SerializeObject(new { productQuantity = storeQuantity }); StringContent request6 = new StringContent(_storeQuantityUpdate, Encoding.UTF8, "application/json"); HttpResponseMessage response6 = client.PatchAsync($"http://shirleyomda-001-site1.etempurl.com/odata/Stores({item.storeID})", request6).Result; #endregion } #endregion //return partial view and design modal //return RedirectToAction("CartList", "Carts"); //return RedirectToAction("BillDetails", new { id = billID }); //return Ok(new { id = billID }); return(Json(new { id = billID })); }