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

            _bll.Categories.Update(CategoryMapper.MapFromExternal(category));
            await _bll.SaveChangesAsync();

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

            category = PublicApi.v1.Mappers.CategoryMapper
                       .MapFromBLL(
                await _bll.Categories.AddAsync(PublicApi.v1.Mappers.CategoryMapper.MapFromExternal(category)));

            await _bll.SaveChangesAsync();

            category = PublicApi.v1.Mappers.CategoryMapper.MapFromBLL(
                _bll.Categories.GetUpdatesAfterUOWSaveChanges(
                    PublicApi.v1.Mappers.CategoryMapper.MapFromExternal(category)));

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