public bool DeleteShoppingCart(int Id, int userId) { try { using (var db = new IconextBookShopEntities()) { var item = db.ShoppingCarts.FirstOrDefault(x => x.Id == Id && x.UserId == userId); if (item != null && item.Quantity > 0) { db.ShoppingCarts.Remove(item); db.SaveChanges(); return true; } else { return false; } } } catch (Exception) { return false; } }
public bool AddItemCart(ShoppingCart shoppingCart) { using (var db = new IconextBookShopEntities()) { var ifHaveInCart = db.ShoppingCarts.FirstOrDefault(x => x.ProductId == shoppingCart.ProductId && x.UserId == shoppingCart.UserId); if (ifHaveInCart != null) { try { ifHaveInCart.Quantity += shoppingCart.Quantity; db.SaveChanges(); return true; } catch (Exception e) { return false; } } else { try { var item = new ShoppingCart(); item.ProductId = shoppingCart.ProductId; item.Quantity = shoppingCart.Quantity; item.UserId = shoppingCart.UserId; item.TimeStamp = DateTime.Now; db.ShoppingCarts.Add(item); db.SaveChanges(); return true; } catch (Exception e) { return false; } } } return false; }
public bool InsertOrderDetail(List<OrderDetail> orderDetails, int orderId) { try { using (var db = new IconextBookShopEntities()) { db.OrderDetails.AddRange(orderDetails); db.SaveChanges(); } return true; } catch (Exception) { return false; } }
public bool Save(Product product) { try { using (var db = new IconextBookShopEntities()) { db.Products.Add(product); db.SaveChanges(); } return true; } catch (Exception e) { return false; } }
public bool DeleteAllCart(int userId) { try { using (var db = new IconextBookShopEntities()) { var shoppingCarts = db.ShoppingCarts.Where(x => x.UserId == userId); db.ShoppingCarts.RemoveRange(shoppingCarts); db.SaveChanges(); return true; } } catch (Exception) { return false; } }
public bool Delete(int productId) { bool isSuccess = true; try { using (var db = new IconextBookShopEntities()) { var product = db.Products.Where(x => x.Id == productId).FirstOrDefault(); product.IsActive = false; db.SaveChanges(); } } catch (Exception e) { isSuccess = false; } return isSuccess; }
public bool UpdateBalance(int productId, int balance) { using (var db = new IconextBookShopEntities()) { var product = db.Products.FirstOrDefault(m => m.Id == productId); if (product != null) { product.Balance = balance; db.SaveChanges(); return true; } else { return false; } } }
public bool UpdateShoppingCartTotal(int id, int userid, int quantityTotal) { try { using (var db = new IconextBookShopEntities()) { var item = db.ShoppingCarts.FirstOrDefault(x => x.Id == id && x.UserId == userid); if (item != null) { item.Quantity = quantityTotal; item.TimeStamp = DateTime.Now; db.SaveChanges(); return true; } else { return false; } } } catch (Exception) { return false; throw; } }