public async Task <IHttpActionResult> PostCustomer(CustomerDTO value) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DbContext.Customers.Add(CustomerTX.ReadFromDTO(new Customer(), value)); await DbContext.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { CustomerId = value.CustomerId }, value)); } catch (Exception ex) { Log.Error("Customer.Post: " + ex); throw; } }
public async Task <IHttpActionResult> GetCustomer(int customerId) { try { CustomerDTO found = await Task.Run(() => { return(CustomerTX.WriteToDTO(DbContext.Customers .AsEnumerable().FirstOrDefault(e => e.CustomerId == customerId))); }); if (found == null) { return(NotFound()); } return(Ok(found)); } catch (Exception ex) { Log.Error("Customer.Get: " + ex); throw; } }