示例#1
0
        public async Task <IActionResult> Post([FromBody] ClientLocation client)
        {
            if (ModelState.IsValid)
            {
                var location = new Location
                {
                    Address = client.Address,
                    City    = client.City
                };

                var newClient = new Client {
                    ClientName = client.ClientName
                };
                try
                {
                    var locationAdded = await _repoLoc.Create(location);

                    newClient.LocationId = locationAdded.LocationId;
                    var addedClient = await _repo.Create(newClient);

                    return(Ok(addedClient));
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Exception thrown while getting client: {ex}");
                }
            }
            return(BadRequest($"Error ocurred"));
        }
示例#2
0
 public async Task <IActionResult> Post([FromBody] Location location)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var addedLocation = _repo.Create(location);
             return(Ok(addedLocation));
         }
         catch (Exception ex)
         {
             _logger.LogError($"Exception thrown while getting location: {ex}");
             return(BadRequest($"Error ocurred"));
         }
     }
     return(BadRequest("Failed to save changes to the database"));
 }