public int Save(Models.MProducts model) { Common.Logger l = new Common.Logger(); string ClassName = "CProducts"; try { DB.Product bs = new DB.Product(); //bs.id = int.Parse(model.id); bs.ProductCode = model.ProductCode; bs.Name = model.Name; bs.tag1 = model.tag1; bs.tag2 = model.tag1; bs.tag3 = model.tag3; bs.costPrice = model.CostPrice; bs.salePrice = model.SalePrice; bs.Manufacturer = model.Manufacturer; bs.Description = model.description; bs.VendorId = int.Parse(model.Vendorld); bs.FiscalYearId = Convert.ToInt32(model.FiscalYearld); bs.eDate = DateTime.Now; bs.WareHouseId = Convert.ToInt32(model.WareHouseId); l.Print(ClassName, Common.LogPointer.Info.ToString(), "Model Values id[" + model.id + "] ProductCode[" + model.ProductCode + "] Name[" + model.Name + "] tag1[" + model.tag1 + "] tag2[ " + model.tag2 + "] tag3 [" + model.tag3 + " ] Manufacture[ " + model.Manufacturer + " ] Description [ " + model.description + "] VendorId [ " + model.Vendorld + "] FiscalYearId [ " + model.FiscalYearld + "] eDate[ " + model.eDate + "]"); obj.Products.InsertOnSubmit(bs); obj.SubmitChanges(); l.Print(ClassName, Common.LogPointer.Info.ToString(), "Record Inserted Successfully"); return(1); } catch (Exception ex) { l.Print(ClassName, Common.LogPointer.Error.ToString(), ex.ToString()); return(-1); } }
public ProductViewModel(DB.Product product) { ID = product.ID; Name = product.Name; Description = product.Description; Cost = product.Cost; GoodsRemain = product.GoodsRemain; Images = JsonSerializer.Deserialize <List <string> >(product.Images); Category = product.Category; }
public void InsertProduct(Product_Location_Price_Contract[] d) { lock (MDB) { try { foreach (var x in d) { var productId = x.Product.ProductId; DB.Product product; if (productId != default(int)) { product = MDB.Products.FirstOrDefault(p => p.ProductId == productId); } else { var locationId = x.Location.LocationId; if (locationId == default(int)) { throw new Xxception("LocationId is not specified"); } //All owners of this location var owners = MDB.OwnerVsLocations.Where(o => o.LocationId == locationId).Select(o => o.OwnerId); //All locations that owners may own var locationIds = MDB.OwnerVsLocations.Where(o => owners.Contains(o.OwnerId)).Select(o => o.LocationId).ToArray(); //Only reuse products from other locations of those owners product = MDB.Products.FirstOrDefault(p => p.Description == x.Product.Description && ( (!p.ProductVsLocations.Any() || p.ProductVsLocations.Any(l => locationIds.Contains(l.LocationId))) && (!p.ProductPriceHistories.Any() || p.ProductPriceHistories.OrderByDescending(r => r.ChangeDate).First().Price == x.Price) ) ); if (product == null) { product = new DB.Product(); x.Product.CopyTo(product, false); MDB.Products.InsertOnSubmit(product); } } var prodVsLoc = new DB.ProductVsLocation() { Product = product, LocationId = x.Location.LocationId }; MDB.ProductVsLocations.InsertOnSubmit(prodVsLoc); var price = new DB.ProductPriceHistory() { Product = product, ChangeDate = DateTime.UtcNow, Price = x.Price }; MDB.ProductPriceHistories.InsertOnSubmit(price); } MDB.SubmitChanges(); } catch (Exception ex) { HandleMyException(ex); } } }