public IActionResult PutDeviceCode(string key, [FromBody] Models.ConData.DeviceCode newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.UserCode != key)) { return(BadRequest()); } this.OnDeviceCodeUpdated(newItem); this.context.DeviceCodes.Update(newItem); this.context.SaveChanges(); var itemToReturn = this.context.DeviceCodes.Where(i => i.UserCode == key); this.OnAfterDeviceCodeUpdated(newItem); return(new ObjectResult(SingleResult.Create(itemToReturn))); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Post([FromBody] Models.ConData.DeviceCode item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnDeviceCodeCreated(item); this.context.DeviceCodes.Add(item); this.context.SaveChanges(); return(Created($"odata/ConData/DeviceCodes/{item.UserCode}", item)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnAfterDeviceCodeUpdated(Models.ConData.DeviceCode item);
partial void OnDeviceCodeDeleted(Models.ConData.DeviceCode item);
partial void OnDeviceCodeCreated(Models.ConData.DeviceCode item);