Exemplo 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."));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetOfferById(int id)
        {
            Offer offer = await _repo.GetOfferById(id);

            OfferForReturnDto offerToReturn = _mapper.Map <OfferForReturnDto>(offer);

            return(Ok(offerToReturn));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SaveOffer([FromQuery] int userId,
                                                    OfferForRegisterDto offerForRegisterDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            Offer newOffer = _mapper.Map <Offer>(offerForRegisterDto);

            _repo.Add(newOffer);

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

                return(Ok(offerForReturnDto));
            }

            return(BadRequest("It's not possible saving offer"));
        }