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; }
public async Task <ActionResult <Response <DtoOrderContent> > > UpdateOrderContent([FromRoute] int idOrderContent, [FromBody] DtoOrderContentUpdate orderContent) { try { if (idOrderContent == 0) { return(BadRequest(new Response <string>() { Error = "IdOrderContent can't be equal to 0", Succes = true })); } if ((await BsOrderContent.GetById <DtoOrderContent>(idOrderContent)) == null) { return(NotFound(new Response <string>() { Error = "the OrderContent doesn't exist", Succes = true })); } if (orderContent == null) { return(BadRequest(new Response <string>() { Error = "The OrderContent can't be null", Succes = true })); } return(Ok(new Response <DtoOrderContent>() { Error = "", Data = await BsOrderContent.Update <DtoOrderContent, DtoOrderContentUpdate>(idOrderContent, orderContent), Succes = true })); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response <string[]>() { Error = e.Message, Data = e.StackTrace.Split("\r\n"), Succes = false })); } }