public async Task <IActionResult> Create([Bind("Id,Name")] Location location) { if (ModelState.IsValid) { await _locationsRepository.AddAsync(location); return(RedirectToAction(nameof(Index))); } return(View(location)); }
public async Task <ActionResult <LocationDto> > PostAsync(CreateLocationDto createLocationDto) { // Note: check if the location with same data exists. if (await _locationsRepo.GetByAsync(createLocationDto.StreetName, createLocationDto.Building, createLocationDto.Flat) != null) { return(StatusCode(StatusCodes.Status409Conflict, "Location with the same data already exist.")); } var location = _mapper.Map <Location>(createLocationDto); await _locationsRepo.AddAsync(location); var locationDto = _mapper.Map <LocationDto>(location); return(CreatedAtAction("Get", new { locationId = location.Id }, locationDto)); }