public override async Task <U> Add <U, V>(V entity) where U : class where V : class { DtoGamme gamme = await BsGamme.GetById <DtoGamme>(BuildMapper <V, DtoOrderContent>().Map <DtoOrderContent>(entity).IdGamme); if (gamme.Stock != 0) { BsGamme.UpdateStock(BuildMapper <DtoGamme, Gamme>().Map <Gamme>(gamme), new DtoStockHisto() { Date = DateTime.Now, Stock = (int)gamme.Stock - BuildMapper <V, DtoOrderContent>().Map <DtoOrderContent>(entity).Quantity }); } return(BuildMapper <OrderContent, U>().Map <U>(await DpOrderContent.Add(BuildMapper <V, OrderContent>().Map <OrderContent>(entity)))); }
private async Task RollBackStock(OrderContent result, DtoOrderContentUpdate entity) { DtoGamme oldGamme = await BsGamme.GetById <DtoGamme>(result.IdGamme); DtoGamme newGamme = await BsGamme.GetById <DtoGamme>((int)entity.IdGamme); await BsGamme.Update <DtoGamme, DtoGammeUpdate>((int)oldGamme.Id, BuildMapper <Gamme, DtoGammeUpdate>().Map <DtoGammeUpdate>(new Gamme() { Stock = oldGamme.Stock + result.Quantity })); await BsGamme.Update <DtoGamme, DtoGammeUpdate>((int)newGamme.Id, BuildMapper <Gamme, DtoGammeUpdate>().Map <DtoGammeUpdate>(new Gamme() { Stock = newGamme.Stock - (int)entity.Quantity })); result.Quantity = (int)entity.Quantity; }