public async Task <IActionResult> EditCustomer(int Id, [FromBody] CustomerResources productResources) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var product = await context.Customers.SingleOrDefaultAsync(x => x.Id == Id); mapper.Map <CustomerResources, Customer>(productResources, product); await context.SaveChangesAsync(); product = await context.Customers.SingleOrDefaultAsync(s => s.Id == product.Id); var result = mapper.Map <Customer, CustomerResources>(product); return(Ok(result)); }
public async Task <IActionResult> CreateCustumer([FromBody] CustomerResources productResources) { // individualResourses.Id = 0; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var product = mapper.Map <CustomerResources, Customer>(productResources); // individual.Id = 0; context.Add(product); await context.SaveChangesAsync(); product = await context.Customers.SingleOrDefaultAsync(s => s.Id == product.Id); var result = mapper.Map <Customer, CustomerResources>(product); return(Ok(result)); }