public async Task <IHttpActionResult> AddUserRole(UserRoleModel userRole) { if (await UserRoleService.UserRoleExists(userRole.Name)) { return(BadRequest("User Role Already Exists")); } else { var usertocreate = new UserRoleModel { Name = userRole.Name }; CommonResponse roleResponse = await UserRoleService.AddNewUserRole(usertocreate); if (roleResponse.IsError) { return(BadRequest("Error In Adding The New Uer Role!")); } else { return(Ok("Successfully Added A New User Role!")); } } }
private async void AddRole_Clicked(object sender, EventArgs e) { bool admin = true; bool dispatch = true; bool courier = true; int roleId = 0; foreach (var item in userRoles) { switch (item.Name) { case "Admin": admin = false; break; case "Dispatcher": dispatch = false; break; case "Courier": courier = false; break; } } string answer = null; if (admin && dispatch && courier) { answer = await DisplayActionSheet("Select new role", "cancel", null, "Courier", "Dispatcher", "Admin"); } else if (admin && dispatch) { answer = await DisplayActionSheet("Select new role", "cancel", null, "Dispatcher", "Admin"); } else if (admin && courier) { answer = await DisplayActionSheet("Select new role", "cancel", null, "Courier", "Admin"); } else if (courier && dispatch) { answer = await DisplayActionSheet("Select new role", "cancel", null, "Dispatcher", "Courier"); } else if (admin) { answer = await DisplayActionSheet("Select new role", "cancel", null, "Admin"); } else if (courier) { answer = await DisplayActionSheet("Select new role", "cancel", null, "Courier"); } else if (dispatch) { answer = await DisplayActionSheet("Select new role", "cancel", null, "Dispatcher"); } switch (answer) { case "Admin": roleId = 2; break; case "Dispatcher": roleId = 5; break; case "Courier": roleId = 4; break; default: await DisplayAlert("Erorr", "Please try again", "ok"); break; } if (roleId > 0) { UserRoleModel ur = new UserRoleModel() { UserID = user.UserID, RoleID = roleId }; if (await userRoleService.AddNewUserRole(ur)) { await DisplayAlert("Succsses", "Created new role for " + user.ToString(), "ok"); GetAllUsersRoles(); } else { await DisplayAlert("Erorr", "Please try again", "ok"); } } }