public ActionResult <StayDTO> Post([FromBody] StayDTO value) { if (value != null && !string.IsNullOrEmpty(value.Name)) { var stay = _mapper.Map <Stay>(value); _context.Stays.Add(stay); _context.SaveChanges(); return(Ok(_mapper.Map <StayDTO>(stay))); } else { return(BadRequest()); } }
public ActionResult <StayDTO> Put(int id, [FromBody] StayDTO stayDto) { var stayToUpdate = _context.Stays.FirstOrDefault(x => x.Id == id); if (stayToUpdate == null) { return(NotFound()); } else { _mapper.Map(stayDto, stayToUpdate); _context.SaveChanges(); return(Ok(_mapper.Map <StayDTO>(stayToUpdate))); } }