public Task ModGild(Gild gild, double Con) { Condiments = new EFRepository <Condiments>(new ApplicationDbContext()); return(Task.Run(() => { var prod = product.FindById(gild.ProductId.Value); prod.Count -= gild.Count; Task.Factory.StartNew(() => { product.Update(prod); }).Wait(); var gld = Gild.FindById(gild.Id); gild.Count += gld.Count; Task.Factory.StartNew(() => { Gild.Update(gild); }).Wait(); var con = Condiments.FindById(gild.CondimentsId.Value); con.Count -= Con; Task.Factory.StartNew(() => { Condiments.Update(con); }).Wait(); GildStatic gl = new GildStatic(); gl.Date = DateTime.Now; gl.CountGild = gild.Count; gl.CountCondiments = Con; Task.Factory.StartNew(() => { GildStatic.Create(gl); }).Wait(); var b = GildStatic.Get(x => x.CountGild == gl.CountGild && x.Date.Day == gl.Date.Day && x.Date.Month == gl.Date.Month && x.Date.Year == gl.Date.Year && x.Date.Hour == gl.Date.Hour && x.Date.Minute == gl.Date.Minute && x.Date.Second == gl.Date.Second).First(); Task.Factory.StartNew(() => { Gild_GildStatic.Create(new db.Gild_GildStatic() { GildId = gild.Id, GildStaticId = b.Id }); }).Wait(); })); }
/// <summary> /// Добавление гильдии /// </summary> /// <param name="gild"></param> public bool GildAdd(Gild gild, double Con) { Condiments = new EFRepository <Condiments>(new ApplicationDbContext()); GildStatic gl = new GildStatic(); if (gild.ProductId != null) { var prod = product.FindById(gild.ProductId.Value); gild.Name = prod.Name; prod.Count -= gild.Count; if (prod.Count < 0) { return(false); } Task.Factory.StartNew(() => { product.Update(prod); }).Wait(); } else { var con = Condiments.FindById(gild.CondimentsId.Value); con.Count -= Con; if (con.Count < 0) { return(false); } Task.Factory.StartNew(() => { Condiments.Update(con); }).Wait(); var sp = Condiments.FindById(gild.CondimentsId.Value); gild.Name = sp.Name; } if (Gild.Get(x => x.Name == gild.Name).Any()) { var gls = Gild.Get(x => x.Name == gild.Name).First(); if (gild.ProductId != null) { gls.Count += gild.Count; gl.CountGild = gild.Count; } else { gls.Count += int.Parse(Con.ToString()); gl.CountGild = Con; gl.CountCondiments = Con; } Task.Factory.StartNew(() => { Gild.Update(gls); }).Wait(); gl.Date = DateTime.Now; Task.Factory.StartNew(() => { GildStatic.Create(gl); }).Wait(); GildStatic b = GildStatic.Get(x => x.CountGild == gl.CountGild && x.Date.Day == gl.Date.Day && x.Date.Month == gl.Date.Month && x.Date.Year == gl.Date.Year && x.Date.Hour == gl.Date.Hour && x.Date.Minute == gl.Date.Minute && x.Date.Second == gl.Date.Second).First(); Task.Factory.StartNew(() => { Gild_GildStatic.Create(new db.Gild_GildStatic() { GildId = gls.Id, GildStaticId = b.Id }); }).Wait(); return(true); } else { if (gild.ProductId != null) { gl.CountGild = gild.Count; } else { gild.Count += int.Parse(Con.ToString()); gl.CountGild = Con; } Task.Factory.StartNew(() => { Gild.Create(gild); }).Wait(); gl.Date = DateTime.Now; Task.Factory.StartNew(() => { GildStatic.Create(gl); }).Wait(); var a = Gild.Get(x => x.Name == gild.Name && x.Count == gild.Count).First(); GildStatic b = GildStatic.Get(x => x.CountGild == gl.CountGild && x.Date.Day == gl.Date.Day && x.Date.Month == gl.Date.Month && x.Date.Year == gl.Date.Year && x.Date.Hour == gl.Date.Hour && x.Date.Minute == gl.Date.Minute && x.Date.Second == gl.Date.Second).First(); Task.Factory.StartNew(() => { Gild_GildStatic.Create(new db.Gild_GildStatic() { GildId = a.Id, GildStaticId = b.Id }); }).Wait(); return(true); } }