Exemplo n.º 1
0
        public async Task <IActionResult> PutInventory(int id, PublicApi.v1.DTO.Inventory inventory)
        {
            if (!ModelState.IsValid || id != inventory.Id || inventory.ShopId != User.GetShopId())
            {
                return(BadRequest());
            }

            _bll.Inventories.Update(InventoryMapper.MapFromExternal(inventory));
            await _bll.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <PublicApi.v1.DTO.InventoryWithProductCount> > PostInventory(PublicApi.v1.DTO.Inventory inventory)
        {
            if (!ModelState.IsValid || inventory.ShopId != User.GetShopId())
            {
                return(BadRequest());
            }

            inventory = PublicApi.v1.Mappers.InventoryMapper
                        .MapFromBLL(await _bll.Inventories.AddAsync(PublicApi.v1.Mappers.InventoryMapper.MapFromExternal(inventory)));

            await _bll.SaveChangesAsync();

            inventory = PublicApi.v1.Mappers.InventoryMapper.MapFromBLL(
                _bll.Inventories.GetUpdatesAfterUOWSaveChanges(PublicApi.v1.Mappers.InventoryMapper.MapFromExternal(inventory)));

            return(CreatedAtAction("GetInventory", new { version = HttpContext.GetRequestedApiVersion().ToString(), id = inventory.Id }, inventory));
        }