public bool UpdateCDetail(tb_DetailCart entity) { try { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult Payment(CartModel entity) { if (ModelState.IsValid) { var cart = SessionHelper.GetSessionCart(); var list = new List <CartItemModel>(); if (cart != null) { list = (List <CartItemModel>)cart; var dCart = new tb_Carts(); dCart.Address = entity.Address; dCart.Date = DateTime.Now; dCart.Description = entity.Description; dCart.Email = entity.Email; dCart.FullName = entity.FullName; dCart.Id = entity.Id; dCart.Modified = DateTime.Now; dCart.PhoneNumber = entity.PhoneNumber; dCart.Status = true; dCart.Total = list.Sum(x => x.Product.Price - ((x.Product.Price * x.Product.Sale) / 100)); dCart.UserId = entity.UserId; dCart.Approval = false; long Id = Dao.Insert(dCart); foreach (var item in list) { var detail = new tb_DetailCart(); detail.CartId = Id; detail.ProductId = item.Product.Id; detail.Quantity = item.Quantity; detail.Price = item.Product.Price - ((item.Product.Price * item.Product.Sale) / 100); Dao.InsertCDetail(detail); } return(Redirect("/hoan-thanh")); } else { ModelState.AddModelError(string.Empty, "Không có sản phẩm nào trong đơn hàng!"); } } return(View(entity)); }
public long InsertCDetail(tb_DetailCart entity) { db.tb_DetailCart.Add(entity); db.SaveChanges(); return(entity.Id); }