Exemplo n.º 1
0
        public async Task <IActionResult> UpdateGood(GoodInsertDto goodForUpdateDto)
        {
            Good updatedGood = await _repo.GetByIDAsync(goodForUpdateDto.Id);

            _mapper.Map(goodForUpdateDto, updatedGood);
            var good = await _repo.UpdateAsync(updatedGood);

            if (good == -1)
            {
                throw new Exception($"Updating good {goodForUpdateDto.Id} failed on save");
            }
            else
            {
                return(Ok(goodForUpdateDto.Id));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SaveGood(GoodInsertDto model)
        {
            Good goodToCreate = _mapper.Map <Good>(model);

            if (goodToCreate.Title == null)
            {
                goodToCreate.Title = "";
            }
            int result = await _repo.InsertAsync(goodToCreate);

            if (result == -1)
            {
                throw new Exception($"couldn't insert this carpet");
            }

            var goodToReturn = _mapper.Map <GoodDto>(goodToCreate);

            return(Ok(new { id = goodToCreate.Id }));
        }