public async Task <IHttpActionResult> Post(UserIdRoleIdVM urVM) { if (urVM == null || string.IsNullOrWhiteSpace(urVM.UserId) || string.IsNullOrWhiteSpace(urVM.RoleId)) { return(BadRequest("The data you inserted is incomplete")); } if (urVM != null) { SqlParameter paramUserId = new SqlParameter("@UserId", urVM.UserId); SqlParameter paramRoleId = new SqlParameter("@RoleId", urVM.RoleId); await db.Database.ExecuteSqlCommandAsync("SP_Save_AspNetUserRoles @UserId, @RoleId", paramUserId, paramRoleId); return(Ok("Ok")); } return(Content(HttpStatusCode.InternalServerError, "Unable to Save Changes")); }
public JsonResult SaveData(UserIdRoleIdVM userIdRoleIdVM) { var client = new HttpClient { BaseAddress = new Uri("http://localhost:50693/api/") }; var myContent = JsonConvert.SerializeObject(userIdRoleIdVM); var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var result = client.PostAsync("apiUserRole/", byteContent).Result; if (result.IsSuccessStatusCode == true) { return(Json(new { value = "Ok" }, JsonRequestBehavior.AllowGet)); } return(Json(new { value = "Error" })); }