public IActionResult PutUser(string key, [FromBody] Models.Crm.User newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.Id != key)) { return(BadRequest()); } this.OnUserUpdated(newItem); this.context.Users.Update(newItem); this.context.SaveChanges(); var itemToReturn = this.context.Users.Where(i => i.Id == key); return(new ObjectResult(SingleResult.Create(itemToReturn))); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Post([FromBody] Models.Crm.User item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnUserCreated(item); this.context.Users.Add(item); this.context.SaveChanges(); return(Created($"odata/Crm/Users/{item.Id}", item)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnUserUpdated(Models.Crm.User item);
partial void OnUserDeleted(Models.Crm.User item);
partial void OnUserCreated(Models.Crm.User item);