public void DeleteBrand(int id) { using (var context = new WebShopContext()) { context.Remove(context.BrandsModel.Select(p => p.BrandId == id)); context.SaveChanges(); } }
public void InsertBrand(BrandsModel brandsModel) { using (var context = new WebShopContext()) { context.BrandsModel.Add(brandsModel); context.SaveChanges(); } }
public void InsertCategory(CategoriesModel categoriesModel) { using (var context = new WebShopContext()) { context.CategoriesModel.Add(categoriesModel); context.SaveChanges(); } }
public void InsertRecipe(RecipesModel recipesModel) { using (var context = new WebShopContext()) { context.RecipesModel.Add(recipesModel); context.SaveChanges(); } }
public void InsertProduct(ProductModel productModel) { using (var context = new WebShopContext()) { context.ProductModel.Add(productModel); context.SaveChanges(); } }
public void DeleteRecipe(int id) { using (var context = new WebShopContext()) { context.Remove(context.RecipesModel.Select(p => p.RecipeId == id)); context.SaveChanges(); } }
public void DeleteOrder(int id) { using (var context = new WebShopContext()) { context.Remove(context.OrdersModel.Select(p => p.OrderId == id)); context.SaveChanges(); } }
public void InsertOrder(OrdersModel ordersModel) { using (var context = new WebShopContext()) { context.OrdersModel.Add(ordersModel); context.SaveChanges(); } }
public void InsertUser(UserModel userModel) { using (var context = new WebShopContext()) { context.UserModel.Add(userModel); context.SaveChanges(); } }
public void InsertContact(ContactModel contactModel) { using (var context = new WebShopContext()) { context.ContactModel.Add(contactModel); context.SaveChanges(); } }
public void DeleteProduct(int id) { using (var context = new WebShopContext()) { context.Remove(context.ProductModel.Select(p => p.ProductId == id)); context.SaveChanges(); } }
public void DeleteCategory(int id) { using (var context = new WebShopContext()) { context.Remove(context.CategoriesModel.Select(p => p.CategoryId == id)); context.SaveChanges(); } }
public UserModel DeleteMaxId(List <UserModel> list) { using (var context = new WebShopContext()) { var id = list.Max(u => u.UserId); UserModel deleteUser = context.UserModel.Where(u => u.UserId == id).FirstOrDefault(); context.UserModel.Remove(deleteUser); context.SaveChanges(); return(deleteUser); } }
public int OrderToBase(int userId, decimal totalPrice) { var dateTime = DateTime.Now; int orderId; using (var context = new WebShopContext()) { OrdersModel order = new OrdersModel(userId, dateTime, totalPrice); context.OrdersModel.Add(order); context.SaveChanges(); OrdersModel orderForUser = context.OrdersModel.Where(p => p.UserId == userId && p.Date == dateTime).FirstOrDefault(); orderId = orderForUser.OrderId; } return(orderId); }
public void UpdateProduct(ProductModel productModel) { using (var context = new WebShopContext()) { try { // context.ProductModel.Attach(productModel); context.Entry(productModel).State = EntityState.Modified; context.SaveChanges(); } catch (Exception ex) { throw; } } }
public void UpdateOrder(OrdersModel ordersModel) { using (var context = new WebShopContext()) { var result = context.OrdersModel.SingleOrDefault(b => b.OrderId == ordersModel.OrderId); if (result != null) { try { context.OrdersModel.Attach(ordersModel); context.Entry(ordersModel).State = EntityState.Modified; context.SaveChanges(); } catch (Exception ex) { throw; } } } }
public void UpdateBrand(BrandsModel brandsModel) { using (var context = new WebShopContext()) { var result = context.BrandsModel.SingleOrDefault(b => b.BrandId == brandsModel.BrandId); if (result != null) { try { context.BrandsModel.Attach(brandsModel); context.Entry(brandsModel).State = EntityState.Modified; context.SaveChanges(); } catch (Exception ex) { throw; } } } }
public void UpdateRecipe(RecipesModel recipesModel) { using (var context = new WebShopContext()) { var result = context.RecipesModel.SingleOrDefault(b => b.RecipeId == recipesModel.RecipeId); if (result != null) { try { context.RecipesModel.Attach(recipesModel); context.Entry(recipesModel).State = EntityState.Modified; context.SaveChanges(); } catch (Exception ex) { throw; } } } }
public void UpdateCategory(CategoriesModel categoriesModel) { using (var context = new WebShopContext()) { var result = context.CategoriesModel.SingleOrDefault(b => b.CategoryId == categoriesModel.CategoryId); if (result != null) { try { context.CategoriesModel.Attach(categoriesModel); context.Entry(categoriesModel).State = EntityState.Modified; context.SaveChanges(); } catch (Exception ex) { throw ex; } } } }
public CheckoutModel ProductToCard(string sessionKey, List <ProductModel> productFromSessionCard) { int userId = Convert.ToInt32(sessionKey); decimal totalPrice = productFromSessionCard.Sum(p => p.SessionPrice); int orderId = OrderToBase(userId, totalPrice); using (var context = new WebShopContext()) { foreach (ProductModel item in productFromSessionCard) { OrderLineModel orderline = new OrderLineModel(orderId, item.ProductId, item.SessionQuantity, item.SessionPrice); context.OrderLineModel.Add(orderline); } context.SaveChanges(); CheckoutModel checkoutModel = new CheckoutModel(); checkoutModel.orderLines = context.OrderLineModel.Where(p => p.OrderId == orderId).ToList(); checkoutModel.order = context.OrdersModel.Where(p => p.OrderId == orderId).FirstOrDefault(); checkoutModel.user = context.UserModel.Where(p => p.UserId == userId).FirstOrDefault(); return(checkoutModel); } }