public IActionResult AddLocation([FromForm] NewLocationViewModel locationData) { if (!ModelState.IsValid || locationData == null) { return(PartialView("_AddLocationPartial", locationData)); } try { var customer = customerService.GetCustomerById(locationData.CustomerId); var newLocation = LocationAddress.Create( locationData.Country, locationData.City, locationData.Street, locationData.StreetNumber, locationData.PostalCode); customerService.AddLocationToCustomer(customer.Id, newLocation); return(PartialView("_AddLocationPartial", locationData)); } catch (CustomerNotFoundException notFound) { logger.LogError("Failed to find the customer entity {@Exception}", notFound.Message); logger.LogDebug("Failed to find the customer entity {@ExceptionMessage}", notFound); return(BadRequest("Failed to find user")); } catch (Exception e) { logger.LogError("Failed to add a new Location {@Exception}", e.Message); logger.LogDebug("Failed to add a new Location {@ExceptionMessage}", e); return(BadRequest("Failed to create a new Location")); } }
public IActionResult AddLocation([FromRoute] string Id) { NewLocationViewModel locationModel = new NewLocationViewModel() { CustomerId = Id }; return(PartialView("_AddLocationPartial", locationModel)); }