Esempio n. 1
0
        public async Task <IActionResult> UpdateOffer([FromQuery] int userId,
                                                      OfferForRegisterDto offerForRegisterDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (await _repo.OfferExists(offerForRegisterDto.Id))
            {
                Offer offer = _mapper.Map <Offer>(offerForRegisterDto);
                _repo.Update(offer);

                if (await _repo.SaveAllAsync())
                {
                    OfferForReturnDto offerForReturnDto = _mapper.Map <OfferForReturnDto>(offer);

                    return(Ok(offerForReturnDto));
                }

                return(BadRequest("It was not possible updating offer"));
            }

            return(BadRequest("Offer doesn't exists."));
        }