public IActionResult Post([FromBody] Models.Crm.UserRole item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnUserRoleCreated(item); this.context.UserRoles.Add(item); this.context.SaveChanges(); var keyUserId = item.UserId; var keyRoleId = item.RoleId; var itemToReturn = this.context.UserRoles.Where(i => i.UserId == keyUserId && i.RoleId == keyRoleId); Request.QueryString = Request.QueryString.Add("$expand", "User,Role"); return(new ObjectResult(SingleResult.Create(itemToReturn)) { StatusCode = 201 }); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult PutUserRole([FromODataUri] string keyUserId, [FromODataUri] string keyRoleId, [FromBody] Models.Crm.UserRole newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.UserId != keyUserId && newItem.RoleId != keyRoleId)) { return(BadRequest()); } this.OnUserRoleUpdated(newItem); this.context.UserRoles.Update(newItem); this.context.SaveChanges(); var itemToReturn = this.context.UserRoles.Where(i => i.UserId == keyUserId && i.RoleId == keyRoleId); Request.QueryString = Request.QueryString.Add("$expand", "User,Role"); return(new ObjectResult(SingleResult.Create(itemToReturn))); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnUserRoleUpdated(Models.Crm.UserRole item);
partial void OnUserRoleDeleted(Models.Crm.UserRole item);