public static bool SetNewPrice(string name, decimal price, string comment, string sellingPointTitle) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (comment == null) { throw new ArgumentNullException(nameof(comment)); } if (sellingPointTitle == null) { throw new ArgumentNullException(nameof(sellingPointTitle)); } if (price <= 0) { throw new ArgumentOutOfRangeException(nameof(price)); } using (var sb = new ShawarmaBaseEntities()) { Shawarma shawarma = sb.Shawarma.FirstOrDefault(sh => sh.ShawarmaName == name); if (shawarma == null) { return(false); } SellingPoint sp = sb.SellingPoint.FirstOrDefault(s => s.ShawarmaTitle == sellingPointTitle); if (sp == null) { return(false); } PriceController pc = sb.PriceController.FirstOrDefault(p => p.ShawarmaId == shawarma.ShawarmaId && p.SellingPointId == sp.SellingPointId); if (pc == null) { pc = new PriceController { Price = price, Comment = comment, SellingPointId = sp.SellingPointId, ShawarmaId = shawarma.ShawarmaId }; sb.PriceController.Add(pc); } else { pc.Price = price; pc.Comment = comment; } return(SaveIt(sb)); } }
public static bool AddSellingPoint(string title, string address, string category) { using (var sb = new ShawarmaBaseEntities()) { var pointCat = sb.SellingPointCategory.FirstOrDefault(selling => selling.SellingPointCategoryName == category); if (pointCat == null) { return(false); } SellingPoint point = new SellingPoint { ShawarmaTitle = title, Address = address, SellingPointCategoryId = pointCat.SellingPointCategoryId }; sb.SellingPoint.Add(point); return(SaveIt(sb)); } }