[4584] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.ServiceModel;
|
---|
| 5 | using HeuristicLab.Services.Authentication.DataTransfer;
|
---|
| 6 | using HeuristicLab.Services.Authentication.DataAccess;
|
---|
| 7 | using System.Data.Linq;
|
---|
[4647] | 8 | using System.Diagnostics;
|
---|
[4584] | 9 |
|
---|
| 10 | namespace HeuristicLab.Services.Authentication
|
---|
| 11 | {
|
---|
| 12 | [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
|
---|
| 13 | public class AuthenticationService : IAuthenticationService
|
---|
| 14 | {
|
---|
[4926] | 15 |
|
---|
[4588] | 16 | #region User
|
---|
[4590] | 17 |
|
---|
[4926] | 18 |
|
---|
[4590] | 19 | public DataTransfer.User GetUser(Guid id)
|
---|
[4584] | 20 | {
|
---|
| 21 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 22 | {
|
---|
[4926] | 23 | var user = db.aspnet_Users.Where(x => x.UserId == id).FirstOrDefault();
|
---|
| 24 | var membership = db.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault();
|
---|
[4584] | 25 |
|
---|
[4647] | 26 |
|
---|
[4926] | 27 | return Convert.ToDataTransfer(user, membership);
|
---|
[4726] | 28 |
|
---|
[4647] | 29 |
|
---|
[4584] | 30 | }
|
---|
[4926] | 31 | }
|
---|
[4647] | 32 |
|
---|
[4979] | 33 | public IEnumerable<DataTransfer.User> GetAllUsers() {
|
---|
| 34 | List<DataTransfer.User> userList = new List<DataTransfer.User>();
|
---|
| 35 | using (UserManagementDataContext db = new UserManagementDataContext()) {
|
---|
| 36 | var users = db.aspnet_Users.ToList<aspnet_User>();
|
---|
| 37 | foreach (aspnet_User user in users) {
|
---|
| 38 | var membership = db.aspnet_Memberships.Where(x => x.UserId == user.UserId).FirstOrDefault();
|
---|
| 39 | userList.Add(Convert.ToDataTransfer(user, membership));
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | return userList;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[4926] | 46 | public IEnumerable<DataTransfer.User> GetUsers(Guid applicationId)
|
---|
| 47 | {
|
---|
| 48 | List<DataTransfer.User> userList = new List<DataTransfer.User>();
|
---|
| 49 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 50 | {
|
---|
| 51 | var users = db.aspnet_Users.Where(x => x.ApplicationId == applicationId).ToList<aspnet_User>();
|
---|
[4647] | 52 |
|
---|
[4926] | 53 | foreach (aspnet_User user in users)
|
---|
| 54 | {
|
---|
| 55 | var membership = db.aspnet_Memberships.Where(x => x.UserId == user.UserId).FirstOrDefault();
|
---|
[4647] | 56 |
|
---|
[4926] | 57 | userList.Add(Convert.ToDataTransfer(user, membership));
|
---|
[4647] | 58 |
|
---|
[4926] | 59 | }
|
---|
[4647] | 60 |
|
---|
| 61 |
|
---|
| 62 |
|
---|
[4926] | 63 | }
|
---|
| 64 | return userList;
|
---|
| 65 | }
|
---|
[4647] | 66 |
|
---|
[4979] | 67 | public Guid AddUser(User user)
|
---|
[4926] | 68 | {
|
---|
| 69 | if (user != null)
|
---|
| 70 | {
|
---|
| 71 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 72 | {
|
---|
[4647] | 73 |
|
---|
[4926] | 74 | aspnet_User eUser = new aspnet_User();
|
---|
| 75 | aspnet_Membership eMembership = new aspnet_Membership();
|
---|
[4647] | 76 |
|
---|
[4926] | 77 | Convert.ToEntity(user, eUser, eMembership);
|
---|
| 78 | try
|
---|
| 79 | {
|
---|
| 80 | db.aspnet_Users.InsertOnSubmit(eUser);
|
---|
| 81 | db.aspnet_Memberships.InsertOnSubmit(eMembership);
|
---|
| 82 | db.SubmitChanges();
|
---|
| 83 | }
|
---|
| 84 | catch (Exception ex)
|
---|
| 85 | {
|
---|
[4962] | 86 | return Guid.Empty;
|
---|
[4926] | 87 | }
|
---|
[4647] | 88 |
|
---|
[4962] | 89 | return user.Id;
|
---|
[4647] | 90 |
|
---|
| 91 |
|
---|
[4926] | 92 | }
|
---|
[4647] | 93 |
|
---|
[4926] | 94 | }
|
---|
[4962] | 95 | return Guid.Empty;
|
---|
[4926] | 96 | }
|
---|
[4584] | 97 |
|
---|
[4926] | 98 | public bool DeleteUser(Guid id)
|
---|
| 99 | {
|
---|
[4647] | 100 |
|
---|
[4926] | 101 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 102 | {
|
---|
| 103 | var user = db.aspnet_Users.Where(x => x.UserId == id).FirstOrDefault();
|
---|
| 104 | var membership = db.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault();
|
---|
| 105 | var userinroles = db.aspnet_UsersInRoles.Where(x => x.UserId == id).ToList<aspnet_UsersInRole>();
|
---|
| 106 | try
|
---|
| 107 | {
|
---|
| 108 | db.aspnet_UsersInRoles.DeleteAllOnSubmit(userinroles);
|
---|
| 109 | db.aspnet_Memberships.DeleteOnSubmit(membership);
|
---|
| 110 | db.aspnet_Users.DeleteOnSubmit(user);
|
---|
| 111 | db.SubmitChanges();
|
---|
| 112 | }
|
---|
| 113 | catch (Exception ex)
|
---|
| 114 | {
|
---|
| 115 | return false;
|
---|
| 116 | }
|
---|
| 117 | return true;
|
---|
[4647] | 118 |
|
---|
[4926] | 119 | }
|
---|
| 120 | return false;
|
---|
| 121 | }
|
---|
[4647] | 122 |
|
---|
| 123 |
|
---|
[4926] | 124 | public bool UpdateUser(User user)
|
---|
| 125 | {
|
---|
| 126 | if (user != null)
|
---|
| 127 | {
|
---|
| 128 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 129 | {
|
---|
[4647] | 130 |
|
---|
[4926] | 131 | var eUser = db.aspnet_Users.Where(x => x.UserId == user.Id).FirstOrDefault();
|
---|
| 132 | var eMembership = db.aspnet_Memberships.Where(x => x.UserId == user.Id).FirstOrDefault();
|
---|
| 133 | Convert.ToEntity(user, eUser, eMembership);
|
---|
| 134 | try
|
---|
| 135 | {
|
---|
[4647] | 136 |
|
---|
[4926] | 137 | db.SubmitChanges();
|
---|
| 138 | }
|
---|
| 139 | catch (Exception ex)
|
---|
| 140 | {
|
---|
| 141 | return false;
|
---|
| 142 | }
|
---|
[4584] | 143 |
|
---|
[4926] | 144 | return true;
|
---|
[4647] | 145 |
|
---|
[4926] | 146 | }
|
---|
[4740] | 147 |
|
---|
[4926] | 148 | }
|
---|
| 149 | return false;
|
---|
| 150 | }
|
---|
[4740] | 151 |
|
---|
[4647] | 152 |
|
---|
[4979] | 153 | public bool AddUserToRole(Guid roleId, Guid userId) {
|
---|
| 154 | using (UserManagementDataContext db = new UserManagementDataContext()) {
|
---|
| 155 | try {
|
---|
| 156 | aspnet_UsersInRole r = new aspnet_UsersInRole();
|
---|
| 157 | r.RoleId = roleId;
|
---|
| 158 | r.UserId = userId;
|
---|
| 159 | db.aspnet_UsersInRoles.InsertOnSubmit(r);
|
---|
| 160 | db.SubmitChanges();
|
---|
| 161 | return true;
|
---|
| 162 | }
|
---|
| 163 | catch (Exception ex) {
|
---|
| 164 | Debug.WriteLine(ex.InnerException);
|
---|
| 165 | return false;
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
[4588] | 169 |
|
---|
[4979] | 170 | public IEnumerable<Guid> GetUsersInRole(Guid roleId) {
|
---|
| 171 | List<Guid> userList = new List<Guid>();
|
---|
| 172 | using (UserManagementDataContext db = new UserManagementDataContext()) {
|
---|
| 173 | try {
|
---|
| 174 | var users = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId).ToList<aspnet_UsersInRole>();
|
---|
| 175 |
|
---|
| 176 | foreach (aspnet_UsersInRole u in users) {
|
---|
| 177 | userList.Add(GetUser(u.UserId).Id);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | }
|
---|
| 181 | catch (Exception ex) {
|
---|
| 182 | Debug.WriteLine(ex.InnerException);
|
---|
| 183 | return new List<Guid>();
|
---|
| 184 |
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | return userList;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /*
|
---|
| 193 | public IEnumerable<User> GetUsersInRole(Guid roleId) {
|
---|
| 194 | List<User> userList = new List<User>();
|
---|
| 195 | using (UserManagementDataContext db = new UserManagementDataContext()) {
|
---|
| 196 | try {
|
---|
| 197 | var users = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId).ToList<aspnet_UsersInRole>();
|
---|
| 198 |
|
---|
| 199 | foreach (aspnet_UsersInRole u in users) {
|
---|
| 200 | userList.Add(GetUser(u.UserId));
|
---|
| 201 |
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | }
|
---|
| 205 | catch (Exception ex) {
|
---|
| 206 | Debug.WriteLine(ex.InnerException);
|
---|
| 207 | return new List<User>();
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | return userList;
|
---|
| 212 | }
|
---|
| 213 | */
|
---|
| 214 |
|
---|
| 215 | public bool IsUserInRole(Guid userId, Guid roleId) {
|
---|
| 216 | bool isInRole = false;
|
---|
| 217 | using (UserManagementDataContext db = new UserManagementDataContext()) {
|
---|
| 218 | var users = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId && x.UserId == userId).ToList<aspnet_UsersInRole>();
|
---|
| 219 | foreach (aspnet_UsersInRole u in users) {
|
---|
| 220 | isInRole = true;
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 | return isInRole;
|
---|
| 224 |
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 |
|
---|
| 228 | public bool RemoveUserFromRole(Guid roleId, Guid userId) {
|
---|
| 229 | using (UserManagementDataContext db = new UserManagementDataContext()) {
|
---|
| 230 | try {
|
---|
| 231 | var role = db.aspnet_UsersInRoles.Where(x => x.RoleId == roleId && x.UserId == userId).FirstOrDefault();
|
---|
| 232 |
|
---|
| 233 | db.aspnet_UsersInRoles.DeleteOnSubmit(role);
|
---|
| 234 | db.SubmitChanges();
|
---|
| 235 | return true;
|
---|
| 236 |
|
---|
| 237 | }
|
---|
| 238 | catch (Exception ex) {
|
---|
| 239 | Debug.WriteLine(ex.InnerException);
|
---|
| 240 | return false;
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 |
|
---|
[4926] | 249 | #endregion
|
---|
[4647] | 250 |
|
---|
| 251 |
|
---|
| 252 |
|
---|
[4926] | 253 | #region Role
|
---|
[4647] | 254 |
|
---|
[4926] | 255 | public Role GetRole(Guid id)
|
---|
| 256 | {
|
---|
| 257 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 258 | {
|
---|
| 259 | var role = db.aspnet_Roles.Where(x => x.RoleId == id).FirstOrDefault();
|
---|
| 260 | return Convert.ToDataTransfer(role);
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
[4647] | 263 |
|
---|
[4979] | 264 | public IEnumerable<Role> GetAllRoles() {
|
---|
| 265 | List<DataTransfer.Role> roleList = new List<DataTransfer.Role>();
|
---|
| 266 | using (UserManagementDataContext db = new UserManagementDataContext()) {
|
---|
| 267 | var roles = db.aspnet_Roles.ToList<aspnet_Role>();
|
---|
| 268 | foreach (aspnet_Role role in roles) {
|
---|
| 269 | roleList.Add(Convert.ToDataTransfer(role));
|
---|
| 270 | }
|
---|
| 271 | }
|
---|
| 272 | return roleList;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[4926] | 275 | public IEnumerable<Role> GetRoles(Guid applicationId)
|
---|
| 276 | {
|
---|
| 277 | List<DataTransfer.Role> roleList = new List<DataTransfer.Role>();
|
---|
| 278 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 279 | {
|
---|
| 280 | var roles = db.aspnet_Roles.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Role>();
|
---|
[4647] | 281 |
|
---|
[4926] | 282 | foreach (aspnet_Role role in roles)
|
---|
| 283 | {
|
---|
| 284 | roleList.Add(Convert.ToDataTransfer(role));
|
---|
| 285 | }
|
---|
[4647] | 286 |
|
---|
[4926] | 287 | }
|
---|
| 288 | return roleList;
|
---|
| 289 | }
|
---|
[4647] | 290 |
|
---|
[4979] | 291 | public Guid AddRole(Role role)
|
---|
[4926] | 292 | {
|
---|
[4647] | 293 |
|
---|
[4926] | 294 | if (role != null)
|
---|
| 295 | {
|
---|
| 296 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 297 | {
|
---|
[4647] | 298 |
|
---|
[4926] | 299 | aspnet_Role eRole = new aspnet_Role();
|
---|
[4647] | 300 |
|
---|
[4926] | 301 | Convert.ToEntity(role, eRole);
|
---|
| 302 | try
|
---|
| 303 | {
|
---|
| 304 | db.aspnet_Roles.InsertOnSubmit(eRole);
|
---|
| 305 | db.SubmitChanges();
|
---|
| 306 | }
|
---|
| 307 | catch (Exception ex)
|
---|
| 308 | {
|
---|
[4962] | 309 | return Guid.Empty;
|
---|
[4926] | 310 | }
|
---|
[4588] | 311 |
|
---|
[4962] | 312 | return role.Id;
|
---|
[4926] | 313 | }
|
---|
[4588] | 314 |
|
---|
[4926] | 315 | }
|
---|
[4962] | 316 | return Guid.Empty;
|
---|
[4926] | 317 | }
|
---|
[4588] | 318 |
|
---|
[4926] | 319 | public bool DeleteRole(Guid id)
|
---|
| 320 | {
|
---|
| 321 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 322 | {
|
---|
| 323 | var role = db.aspnet_Roles.Where(x => x.RoleId == id).FirstOrDefault();
|
---|
[4588] | 324 |
|
---|
| 325 |
|
---|
[4926] | 326 | try
|
---|
| 327 | {
|
---|
| 328 | db.aspnet_Roles.DeleteOnSubmit(role);
|
---|
| 329 | db.SubmitChanges();
|
---|
| 330 | }
|
---|
| 331 | catch (Exception ex)
|
---|
| 332 | {
|
---|
| 333 | return false;
|
---|
| 334 | }
|
---|
| 335 | return true;
|
---|
[4647] | 336 |
|
---|
| 337 |
|
---|
[4926] | 338 | }
|
---|
| 339 | }
|
---|
[4647] | 340 |
|
---|
[4979] | 341 | public IEnumerable<Guid> GetRolesForUser(Guid userId) {
|
---|
| 342 | List<Guid> roleList = new List<Guid>();
|
---|
| 343 | using (UserManagementDataContext db = new UserManagementDataContext()) {
|
---|
| 344 | try {
|
---|
| 345 | var roles = db.aspnet_UsersInRoles.Where(x => x.UserId == userId).ToList<aspnet_UsersInRole>();
|
---|
| 346 | foreach (aspnet_UsersInRole r in roles) {
|
---|
| 347 | roleList.Add(GetRole(r.RoleId).Id);
|
---|
| 348 | }
|
---|
[4926] | 349 | }
|
---|
[4979] | 350 | catch (Exception ex) {
|
---|
| 351 | Debug.WriteLine(ex.InnerException);
|
---|
| 352 | return new List<Guid>();
|
---|
| 353 | }
|
---|
| 354 | }
|
---|
[4647] | 355 |
|
---|
[4979] | 356 | return roleList;
|
---|
[4647] | 357 |
|
---|
[4926] | 358 | }
|
---|
[4588] | 359 |
|
---|
[4979] | 360 | /*
|
---|
[4926] | 361 | public IEnumerable<Role> GetRolesForUser(Guid userId)
|
---|
| 362 | {
|
---|
| 363 | List<Role> roleList = new List<Role>();
|
---|
| 364 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 365 | {
|
---|
| 366 | try
|
---|
| 367 | {
|
---|
[4979] | 368 | var roles = db.aspnet_UsersInRoles.Where(x => x.UserId == userId).ToList<aspnet_UsersINRole>();
|
---|
[4647] | 369 |
|
---|
[4926] | 370 | foreach (aspnet_UsersInRole r in roles)
|
---|
| 371 | {
|
---|
| 372 | roleList.Add(GetRole(r.RoleId));
|
---|
[4647] | 373 |
|
---|
[4926] | 374 | }
|
---|
[4647] | 375 |
|
---|
[4926] | 376 | }
|
---|
| 377 | catch (Exception ex)
|
---|
| 378 | {
|
---|
| 379 | Debug.WriteLine(ex.InnerException);
|
---|
| 380 | return new List<Role>();
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
[4647] | 383 |
|
---|
[4926] | 384 | return roleList;
|
---|
| 385 | }
|
---|
[4979] | 386 | */
|
---|
[4647] | 387 |
|
---|
| 388 |
|
---|
| 389 |
|
---|
[4926] | 390 | public bool UpdateRole(Role role)
|
---|
| 391 | {
|
---|
| 392 | if (role != null)
|
---|
| 393 | {
|
---|
| 394 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 395 | {
|
---|
[4647] | 396 |
|
---|
[4926] | 397 | var eRole = db.aspnet_Roles.Where(x => x.RoleId == role.Id).FirstOrDefault();
|
---|
[4647] | 398 |
|
---|
[4926] | 399 | Convert.ToEntity(role, eRole);
|
---|
| 400 | try
|
---|
| 401 | {
|
---|
[4647] | 402 |
|
---|
[4926] | 403 | db.SubmitChanges();
|
---|
| 404 | }
|
---|
| 405 | catch (Exception ex)
|
---|
| 406 | {
|
---|
| 407 | return false;
|
---|
| 408 | }
|
---|
[4647] | 409 |
|
---|
[4926] | 410 | return true;
|
---|
[4647] | 411 |
|
---|
[4926] | 412 | }
|
---|
[4647] | 413 |
|
---|
[4926] | 414 | }
|
---|
| 415 | return false;
|
---|
| 416 | }
|
---|
[4647] | 417 |
|
---|
| 418 |
|
---|
| 419 |
|
---|
[4926] | 420 | #endregion
|
---|
[4647] | 421 |
|
---|
| 422 |
|
---|
[4588] | 423 |
|
---|
[4926] | 424 | #region Application
|
---|
[4647] | 425 |
|
---|
[4979] | 426 | public Guid AddApplication(Application application)
|
---|
[4926] | 427 | {
|
---|
| 428 | if (application != null)
|
---|
| 429 | {
|
---|
| 430 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 431 | {
|
---|
[4647] | 432 |
|
---|
[4926] | 433 | aspnet_Application eApplication = new aspnet_Application();
|
---|
[4647] | 434 |
|
---|
[4926] | 435 | Convert.ToEntity(application, eApplication);
|
---|
| 436 | try
|
---|
| 437 | {
|
---|
| 438 | db.aspnet_Applications.InsertOnSubmit(eApplication);
|
---|
| 439 | db.SubmitChanges();
|
---|
| 440 | }
|
---|
| 441 | catch (Exception ex)
|
---|
| 442 | {
|
---|
[4962] | 443 | return Guid.Empty;
|
---|
[4926] | 444 | }
|
---|
[4647] | 445 |
|
---|
[4962] | 446 | return application.Id;
|
---|
[4647] | 447 |
|
---|
[4926] | 448 | }
|
---|
[4647] | 449 |
|
---|
[4926] | 450 | }
|
---|
[4962] | 451 | return Guid.Empty;
|
---|
[4926] | 452 | }
|
---|
[4647] | 453 |
|
---|
[4926] | 454 | public bool UpdateApplication(Application application)
|
---|
| 455 | {
|
---|
| 456 | if (application != null)
|
---|
| 457 | {
|
---|
| 458 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 459 | {
|
---|
[4647] | 460 |
|
---|
[4926] | 461 | var eApplication = db.aspnet_Applications.Where(x => x.ApplicationId == application.Id).FirstOrDefault();
|
---|
[4647] | 462 |
|
---|
[4926] | 463 | Convert.ToEntity(application, eApplication);
|
---|
| 464 | try
|
---|
| 465 | {
|
---|
[4647] | 466 |
|
---|
[4926] | 467 | db.SubmitChanges();
|
---|
| 468 | }
|
---|
| 469 | catch (Exception ex)
|
---|
| 470 | {
|
---|
| 471 | return false;
|
---|
| 472 | }
|
---|
[4647] | 473 |
|
---|
[4926] | 474 | return true;
|
---|
[4647] | 475 |
|
---|
[4926] | 476 | }
|
---|
[4647] | 477 |
|
---|
[4926] | 478 | }
|
---|
| 479 | return false;
|
---|
| 480 | }
|
---|
[4726] | 481 |
|
---|
| 482 |
|
---|
[4926] | 483 | public bool DeleteApplication(Guid applicationId)
|
---|
| 484 | {
|
---|
| 485 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 486 | {
|
---|
| 487 | var users = db.aspnet_Users.Where(x => x.ApplicationId == applicationId).ToList<aspnet_User>();
|
---|
| 488 | var memberships = db.aspnet_Memberships.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Membership>();
|
---|
[4726] | 489 |
|
---|
[4926] | 490 | var roles = db.aspnet_Roles.Where(x => x.ApplicationId == applicationId).ToList<aspnet_Role>();
|
---|
| 491 | var application = db.aspnet_Applications.Where(x => x.ApplicationId == applicationId).FirstOrDefault();
|
---|
[4726] | 492 |
|
---|
[4926] | 493 | try
|
---|
| 494 | {
|
---|
| 495 | foreach (aspnet_User u in users)
|
---|
| 496 | {
|
---|
| 497 | var userinroles = db.aspnet_UsersInRoles.Where(x => x.UserId == u.UserId).ToList<aspnet_UsersInRole>();
|
---|
| 498 | db.aspnet_UsersInRoles.DeleteAllOnSubmit(userinroles);
|
---|
| 499 | }
|
---|
[4726] | 500 |
|
---|
[4926] | 501 | db.aspnet_Memberships.DeleteAllOnSubmit(memberships);
|
---|
| 502 | db.aspnet_Users.DeleteAllOnSubmit(users);
|
---|
| 503 | db.aspnet_Roles.DeleteAllOnSubmit(roles);
|
---|
| 504 | db.aspnet_Applications.DeleteOnSubmit(application);
|
---|
| 505 | db.SubmitChanges();
|
---|
| 506 | }
|
---|
| 507 | catch (Exception ex)
|
---|
| 508 | {
|
---|
| 509 | return false;
|
---|
| 510 | }
|
---|
| 511 | return true;
|
---|
[4726] | 512 |
|
---|
| 513 |
|
---|
[4926] | 514 | }
|
---|
| 515 | return false;
|
---|
| 516 | }
|
---|
[4726] | 517 |
|
---|
[4926] | 518 | public Application GetApplication(Guid id)
|
---|
| 519 | {
|
---|
| 520 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 521 | {
|
---|
| 522 | var application = db.aspnet_Applications.Where(x => x.ApplicationId == id).FirstOrDefault();
|
---|
| 523 | return Convert.ToDataTransfer(application);
|
---|
| 524 | }
|
---|
| 525 | }
|
---|
[4647] | 526 |
|
---|
[4926] | 527 | public IEnumerable<DataTransfer.Application> GetApplications()
|
---|
| 528 | {
|
---|
| 529 | List<DataTransfer.Application> applicationList = new List<DataTransfer.Application>();
|
---|
| 530 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 531 | {
|
---|
| 532 | var apps = db.aspnet_Applications.ToList<aspnet_Application>();
|
---|
[4647] | 533 |
|
---|
[4926] | 534 | foreach (aspnet_Application app in apps)
|
---|
| 535 | {
|
---|
| 536 | applicationList.Add(Convert.ToDataTransfer(app));
|
---|
| 537 | }
|
---|
[4647] | 538 |
|
---|
[4926] | 539 | }
|
---|
| 540 | return applicationList;
|
---|
| 541 | }
|
---|
[4647] | 542 |
|
---|
[4926] | 543 | #endregion
|
---|
| 544 | }
|
---|
[4647] | 545 |
|
---|
[4584] | 546 | }
|
---|
[4590] | 547 |
|
---|