public IActionResult CreateResturant([FromBody] ResturantDTO resturant) { if (resturant == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var resturantEntity = Mapper.Map <Resturant>(resturant); _resturantRepository.AddResturant(resturantEntity); if (!_resturantRepository.Save()) { return(StatusCode(500, "A problem happened when trying to save the entity.")); } var createdResturant = Mapper.Map <ResturantDTO>(resturantEntity); return(CreatedAtRoute("GetResturant", new { createdResturant.Id, includeReviews = true }, createdResturant)); }
public async Task <ActionResult> AddRestustrant([FromBody] ResturantDTO resturantDTO) { if (resturantDTO is null) { return(BadRequest()); } var resturant = Assembler.MapToModel(resturantDTO); await _resturantRepository.AddAsync(resturant); return(CreatedAtAction(nameof(AddRestustrant), new { id = resturant.ResturantId }, null)); }
public async Task <ActionResult> UpdateRestustrant(Guid resturantId, [FromBody] ResturantDTO resturantDTO) { if (resturantId == Guid.Empty || resturantDTO is null) { return(BadRequest()); } var resturantToUpdate = await _resturantRepository.FindAsync(resturantId); if (resturantToUpdate is null) { return(NotFound()); } resturantToUpdate.Name = resturantDTO.Name; resturantToUpdate.CityId = resturantDTO.CityId; resturantToUpdate.FullAddress = resturantDTO.FullAddress; await _resturantRepository.UpdateAsync(resturantToUpdate); return(CreatedAtAction(nameof(UpdateRestustrant), new { id = resturantToUpdate.ResturantId }, null)); }