public IActionResult CreateLocation([FromBody] LocationInsertDto location) { if (location == null) { return(BadRequest()); } if (_locationRepository.isLocationExist(location.Name)) { ModelState.AddModelError(nameof(LocationInsertDto), "Locaiton Name Already Exist"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var locationEntity = Mapper.Map <Location>(location); _locationRepository.Add(locationEntity); if (!_locationRepository.Commit()) { throw new Exception("Creating a Locaiton Failed"); } var locationtoReturn = Mapper.Map <LocationViewModel>(locationEntity); return(CreatedAtRoute("GetLocation", new { id = locationtoReturn.Id }, locationtoReturn)); }
public string Add(Location location) { string ret; try { if (location.movie.active == true && location.movie.amount > 0) { location.locationDate = DateTime.Now; location.locationDevolution = location.locationDate.AddDays(3); _locationRepository.Add(location); location.movie.amount = location.movie.amount - 1; _locationRepository.Commit(); ret = "Locação feita com sucesso, com devolução marcada para : " + location.locationDevolution; } else { ret = "Filme indisponível"; } return(ret); } catch (Exception ex) { _logger.LogError(ex, "Erro ao adcionar Locação"); throw; } }