public void DelLabel(int id, string label) { var ctx = new ShopContext(); var temp = ctx.Label.Where(x => x.Id == id).FirstOrDefault(); temp.Name = label; ctx.SaveChanges(); }
public void AddLabel(string label) { var ctx = new ShopContext(); var temp = new Label(); temp.Name = label; ctx.Label.Add(temp); ctx.SaveChanges(); }
public bool DeleteProduct(int id) { try { var ctx = new ShopContext(); ctx.Product.Remove(ctx.Product.Where(x => x.Id == id).FirstOrDefault()); ctx.SaveChanges(); return true; } catch (Exception) { return false; } }
public bool DelSale(int id, int count) { try { var ctx = new ShopContext(); var temp = ctx.Product.Where(x => x.Id == id).FirstOrDefault(); temp.Count += count; ctx.SaveChanges(); return true; } catch (Exception) { return false; } }
public bool AddProduct(Product product, string label) { try { var ctx = new ShopContext(); var temp = ctx.Label.Where(x => x.Name == label).SingleOrDefault(); product.Label = temp; ctx.Product.Add(product); ctx.SaveChanges(); return true; } catch (Exception) { return false; } }
public bool AddSale(SaleProduct sale, string label) { try { var ctx = new ShopContext(); var temp = ctx.Label.Where(x => x.Name == label).FirstOrDefault(); sale.Label = temp; sale.Price = (sale.Price * sale.Count) - sale.Discount; ctx.SaleProduct.Add(sale); ctx.SaveChanges(); return true; } catch (Exception) { return false; } }
public void ZeroCountProduct() { var ctx = new ShopContext(); foreach (var item in ctx.Product) { item.Count = 0; } ctx.SaveChanges(); }
public bool SaveProduct(Product product, string label) { try { var ctx = new ShopContext(); var temp = ctx.Label.Where(x => x.Name == label).FirstOrDefault(); var tempProduct = ctx.Product.Where(x => x.Id == product.Id).FirstOrDefault(); tempProduct.Label = temp; tempProduct.Name = product.Name; tempProduct.Volume = product.Volume; tempProduct.Price = product.Price; tempProduct.Count = product.Count; ctx.SaveChanges(); return true; } catch (Exception) { return false; } }