public async Task <IActionResult> Create([FromBody] NewServiceDto service) { var result = dataContext.Add(mapper.Map <Service>(service)); await dataContext.SaveChangesAsync(); return(Ok(result)); }
public IHttpActionResult CreateNewService(NewServiceDto newService) { // Grab Customer var customer = _context.Customers.Include(c => c.MembershipType).Single( c => c.Id == newService.CustomerId); if (customer == null) return BadRequest("Invalid Customer"); // New Service var service = new Service { RelatedCustomer = customer, Name = newService.Name, BeginService = DateTime.Now, // Calculate End Service Dynamically based on customer membership plan EndService = DateTime.Now.AddMonths(customer.MembershipType.DurationInMonths) }; _context.Services.Add(service); _context.SaveChanges(); return Ok(); }
public async Task <IActionResult> Update([FromRoute] long id, [FromBody] NewServiceDto updated) { var service = dataContext.Set <Service>().SingleOrDefault(s => s.Id == id); if (service == null) { return(BadRequest()); } mapper.Map(updated, service); dataContext.Update(service); await dataContext.SaveChangesAsync(); return(Ok(service)); }