Ejemplo n.º 1
0
        public async Task <IActionResult> CreateGig([FromBody] SavedGigResource savedGigResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var gig = _mapper.Map <SavedGigResource, Gig>(savedGigResource);

            _unitOfWork.GigRepository.AddAsync(gig);
            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map <Gig, SavedGigResource>(gig);

            return(Ok(result));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateGig(int id, [FromBody] SavedGigResource savedGigResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var gig = await _unitOfWork.GigRepository.GetGigWithId(id);

            if (gig == null)
            {
                return(NotFound(id));
            }
            _mapper.Map <SavedGigResource, Gig>(savedGigResource, gig);

            await _unitOfWork.CompleteAsync();

            gig = await _unitOfWork.GigRepository.GetGigWithId(gig.Id);

            var result = _mapper.Map <Gig, SavedGigResource>(gig);

            return(Ok(result));
        }