//приход на склад сырья public Task PrihodSyr(Product obj) { return(Task.Run(() => { var prodo = product.FindById(obj.Id); RawMaterialStatistics stat = new RawMaterialStatistics(); stat.Id = 0; stat.Count = obj.Count; stat.Date = DateTime.Now; prodo.Count += obj.Count; Task.Factory.StartNew(() => { product.Update(prodo); }).Wait(); Task.Factory.StartNew(() => { statistic.Create(stat); }).Wait(); var st = statistic.Get(x => x.Count == stat.Count && x.Date.Value.Day == stat.Date.Value.Day && x.Date.Value.Month == stat.Date.Value.Month && x.Date.Value.Year == stat.Date.Value.Year && x.Date.Value.Hour == stat.Date.Value.Hour && x.Date.Value.Minute == stat.Date.Value.Minute && x.Date.Value.Second == stat.Date.Value.Second).First(); Raw_Product rw = new db.Raw_Product(); rw.ProductId = obj.Id; rw.RawId = st.Id; Task.Factory.StartNew(() => { Raw_Product.Create(rw); }).Wait(); })); }
public Task AddProduct(Product obj) { return(Task.Run(() => { if (product.Get(x => x.Name == obj.Name).Any()) { var pr = product.Get(x => x.Name == obj.Name).First(); RawMaterialStatistics stat = new RawMaterialStatistics(); stat.Count = obj.Count; stat.Date = DateTime.Now; pr.Count += obj.Count; Task.Factory.StartNew(() => { product.Update(pr); }).Wait(); Task.Factory.StartNew(() => { statistic.Create(stat); }).Wait(); var st = statistic.Get(x => x.Count == stat.Count && x.Date.Value.Day == stat.Date.Value.Day && x.Date.Value.Month == stat.Date.Value.Month && x.Date.Value.Year == stat.Date.Value.Year && x.Date.Value.Hour == stat.Date.Value.Hour && x.Date.Value.Minute == stat.Date.Value.Minute && x.Date.Value.Second == stat.Date.Value.Second).First(); var prod = product.Get(x => x.Count == obj.Count && x.Name == obj.Name).First(); var rw = new db.Raw_Product(); rw.ProductId = prod.Id; rw.RawId = st.Id; Task.Factory.StartNew(() => { Raw_Product.Create(rw); }).Wait(); } else { RawMaterialStatistics stat = new RawMaterialStatistics(); stat.Count = obj.Count; stat.Date = DateTime.Now; Task.Factory.StartNew(() => { product.Create(obj); }).Wait(); } })); }