Beispiel #1
0
        public override async Task <U> Update <U, V>(int id, V entity) where U : class where V : class
        {
            var sourceEntity = await DpOrderContent.GetById(id);

            var updateEntity = BuildMapper <V, DtoOrderContentUpdate>().Map <DtoOrderContentUpdate>(entity);

            if (VerifyEntityUpdate(updateEntity.IdGamme, sourceEntity.IdGamme))
            {
                await RollBackStock(sourceEntity, updateEntity);

                sourceEntity.IdGamme = (int)updateEntity.IdGamme;
            }
            if (VerifyEntityUpdate(updateEntity.IdOrder, sourceEntity.IdOrder))
            {
                sourceEntity.IdOrder = (int)updateEntity.IdOrder;
            }
            if (VerifyEntityUpdate(updateEntity.Quantity, sourceEntity.Quantity))
            {
                Gamme gamme = await BsGamme.GetById <Gamme>(sourceEntity.IdGamme);

                gamme.IdProducer = 1;
                int diffStock = sourceEntity.Quantity - (int)updateEntity.Quantity;
                await BsGamme.Update <DtoGamme, DtoGammeUpdate>(sourceEntity.IdGamme, new DtoGammeUpdate()
                {
                    Stock = (gamme.Stock + diffStock)
                });

                sourceEntity.Quantity = (int)updateEntity.Quantity;
            }
            return(await base.Update <U, OrderContent>(id, sourceEntity));
        }