// POST api/values public IHttpActionResult CreateService([FromBody] AllValueService allservice) { Service service = new Service(); service.ServiceId = allservice.ServiceId; service.Name = allservice.Name; service.Location = allservice.Location; ServiceType serviceType = new ServiceType(); serviceType.ServiceId = allservice.ServiceId; serviceType.ServiceType1 = allservice.ServiceType1; serviceType.Price = allservice.Price; serviceType.AeraToSupport = allservice.AeraToSupport; if (service.Name.Length > 100) { return(Content(HttpStatusCode.BadRequest, "Name is too long")); } else { Models.Services.Add(service); Models.ServiceTypes.Add(serviceType); } Models.SaveChanges(); return(Content(HttpStatusCode.Created, "")); }
// PUT api/values/5 public IHttpActionResult ReplaceService(int id, [FromBody] AllValueService replaceService) { var removeService = Models.Services.Where(services => services.ServiceId == id).FirstOrDefault(); var removeServicetype = Models.ServiceTypes.Where(servicetypes => servicetypes.ServiceId == id).FirstOrDefault(); Models.Services.Remove(removeService); Models.ServiceTypes.Remove(removeServicetype); Service service = new Service(); service.ServiceId = replaceService.ServiceId; service.Name = replaceService.Name; service.Location = replaceService.Location; ServiceType serviceType = new ServiceType(); serviceType.ServiceId = replaceService.ServiceId; serviceType.ServiceType1 = replaceService.ServiceType1; serviceType.Price = replaceService.Price; serviceType.AeraToSupport = replaceService.AeraToSupport; if (service.Name.Length > 100) { return(Content(HttpStatusCode.BadRequest, "Name is too long")); } Models.Services.Add(service); Models.ServiceTypes.Add(serviceType); Models.SaveChanges(); return(Content(HttpStatusCode.Accepted, "")); }
public IHttpActionResult UpdateService(int id, [FromBody] AllValueService allservice) { return(ReplaceService(id, allservice)); }