[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 | {
|
---|
[4588] | 15 | #region User
|
---|
[4590] | 16 |
|
---|
| 17 | public DataTransfer.User GetUser(Guid id)
|
---|
[4584] | 18 | {
|
---|
| 19 | using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 20 | {
|
---|
[4740] | 21 | var user = db.aspnet_Users.Where(x => x.UserId == id).FirstOrDefault();
|
---|
| 22 | var membership = db.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault();
|
---|
| 23 |
|
---|
[4584] | 24 |
|
---|
[4740] | 25 | return Convert.ToDataTransfer(user, membership);
|
---|
| 26 | //Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
|
---|
[4647] | 27 |
|
---|
[4740] | 28 | //var User = from item in UserTable
|
---|
| 29 | // where item.UserId == id
|
---|
| 30 | // select item;
|
---|
| 31 | //aspnet_User eUser = User.Single();
|
---|
[4726] | 32 |
|
---|
[4740] | 33 | //User user = Convert.ToDataTransfer((aspnet_User)eUser);
|
---|
[4647] | 34 |
|
---|
[4740] | 35 | //if (user == null) { return null; }
|
---|
[4647] | 36 |
|
---|
[4740] | 37 | //Table<aspnet_Membership> MembershipTable = db.GetTable<aspnet_Membership>();
|
---|
[4647] | 38 |
|
---|
[4740] | 39 | //var Membership = from item in MembershipTable
|
---|
| 40 | // where item.UserId == id
|
---|
| 41 | // select item;
|
---|
[4647] | 42 |
|
---|
[4740] | 43 | //Membership membership = Convert.ToDataTransfer((aspnet_Membership)eUser.aspnet_Membership);
|
---|
[4647] | 44 |
|
---|
[4740] | 45 | //if (membership == null) { return null; }
|
---|
| 46 | //user.Membership = membership;
|
---|
[4647] | 47 |
|
---|
[4740] | 48 | //return user;
|
---|
[4647] | 49 |
|
---|
[4584] | 50 | }
|
---|
[4740] | 51 | }
|
---|
[4647] | 52 |
|
---|
[4740] | 53 | #endregion
|
---|
[4647] | 54 |
|
---|
| 55 |
|
---|
[4740] | 56 | //public DataTransfer.User GetUser(Guid applicationId, string userName)
|
---|
| 57 | //{
|
---|
| 58 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 59 | // {
|
---|
| 60 | // try
|
---|
| 61 | // {
|
---|
| 62 | // Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
|
---|
[4647] | 63 |
|
---|
[4740] | 64 | // var User = from item in UserTable
|
---|
| 65 | // where item.UserName == userName && item.ApplicationId == applicationId
|
---|
| 66 | // select item;
|
---|
[4647] | 67 |
|
---|
[4740] | 68 | // User user = Convert.ToDataTransfer((aspnet_User)User.Single());
|
---|
[4647] | 69 |
|
---|
[4740] | 70 | // if (user == null) { return null; }
|
---|
[4647] | 71 |
|
---|
[4740] | 72 | // Table<aspnet_Membership> MembershipTable = db.GetTable<aspnet_Membership>();
|
---|
[4647] | 73 |
|
---|
[4740] | 74 | // var Membership = from item in MembershipTable
|
---|
| 75 | // where item.UserId == user.UserId
|
---|
| 76 | // select item;
|
---|
[4647] | 77 |
|
---|
[4740] | 78 | // Membership membership = Convert.ToDataTransfer((aspnet_Membership)Membership.Single());
|
---|
[4647] | 79 |
|
---|
[4740] | 80 | // if (membership == null) { return null; }
|
---|
| 81 | // user.Membership = membership;
|
---|
[4647] | 82 |
|
---|
[4740] | 83 | // return user;
|
---|
[4647] | 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
[4584] | 87 |
|
---|
[4740] | 88 | // }
|
---|
| 89 | // catch (Exception ex)
|
---|
| 90 | // {
|
---|
| 91 | // Debug.WriteLine(ex.InnerException);
|
---|
| 92 | // return null;
|
---|
| 93 | // }
|
---|
| 94 | // }
|
---|
| 95 | //}
|
---|
[4647] | 96 |
|
---|
[4740] | 97 | //public IEnumerable<DataTransfer.User> GetUsers(Guid applicationId)
|
---|
| 98 | //{
|
---|
| 99 | // List<DataTransfer.User> UserList = new List<DataTransfer.User>();
|
---|
| 100 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 101 | // {
|
---|
| 102 | // try
|
---|
| 103 | // {
|
---|
| 104 | // Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
|
---|
| 105 | // var Users = from item in UserTable
|
---|
| 106 | // where item.ApplicationId == applicationId
|
---|
| 107 | // select item;
|
---|
| 108 | // foreach (var eUser in Users)
|
---|
| 109 | // {
|
---|
[4647] | 110 |
|
---|
[4740] | 111 | // User user = Convert.ToDataTransfer(eUser);
|
---|
[4647] | 112 |
|
---|
[4740] | 113 | // if (user== null) { return null; }
|
---|
[4647] | 114 |
|
---|
[4740] | 115 | // //Table<aspnet_Membership> MembershipTable = db.GetTable<aspnet_Membership>();
|
---|
[4647] | 116 |
|
---|
[4740] | 117 | // //var Membership = from item in MembershipTable
|
---|
| 118 | // // where item.UserId == user.UserId
|
---|
| 119 | // // select item;
|
---|
[4647] | 120 |
|
---|
[4740] | 121 | // Membership membership = Convert.ToDataTransfer((aspnet_Membership)eUser.aspnet_Membership);
|
---|
[4584] | 122 |
|
---|
[4740] | 123 | // if (membership == null) { return null; }
|
---|
| 124 | // user.Membership = membership;
|
---|
[4647] | 125 |
|
---|
[4740] | 126 | // UserList.Add(user);
|
---|
| 127 | // }
|
---|
| 128 | // }
|
---|
| 129 | // catch (Exception ex)
|
---|
| 130 | // {
|
---|
| 131 | // Debug.WriteLine(ex.InnerException);
|
---|
| 132 | // return new List<User>();
|
---|
| 133 | // }
|
---|
| 134 | // }
|
---|
| 135 |
|
---|
| 136 | // return UserList;
|
---|
| 137 | //}
|
---|
| 138 | //public bool InsertUser(User user)
|
---|
| 139 | //{
|
---|
| 140 | // if (user != null)
|
---|
| 141 | // {
|
---|
| 142 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 143 | // {
|
---|
| 144 | // try
|
---|
| 145 | // {
|
---|
| 146 |
|
---|
| 147 | // Guid? userId = null;
|
---|
| 148 | // Application application = GetApplication(user.ApplicationId);
|
---|
| 149 | // if(application == null){return false;}
|
---|
| 150 | // if (user.Membership == null) { return false; }
|
---|
[4647] | 151 |
|
---|
[4740] | 152 | // int? passwordFormat = 1;
|
---|
| 153 | // int? uniqueEmail = null;
|
---|
| 154 | // int result = db.aspnet_Membership_CreateUser(application.ApplicationName, user.UserName, user.Membership.Password, user.Membership.PasswordSalt, user.Membership.Email, user.Membership.PasswordQuestion, user.Membership.PasswordAnswer, user.Membership.IsApproved, DateTime.UtcNow, DateTime.Now, uniqueEmail, passwordFormat, ref userId);
|
---|
[4647] | 155 |
|
---|
[4740] | 156 | // if (result != 0)
|
---|
| 157 | // {
|
---|
| 158 | // return false;
|
---|
| 159 | // }
|
---|
[4647] | 160 |
|
---|
[4740] | 161 | // if (userId != null)
|
---|
| 162 | // {
|
---|
| 163 | // return true;
|
---|
| 164 | // }
|
---|
| 165 | // else
|
---|
| 166 | // {
|
---|
| 167 | // return false;
|
---|
| 168 | // }
|
---|
| 169 | // }
|
---|
| 170 | // catch (Exception ex)
|
---|
| 171 | // {
|
---|
| 172 | // Debug.WriteLine(ex.InnerException);
|
---|
| 173 | // return false;
|
---|
| 174 | // }
|
---|
| 175 | // }
|
---|
[4647] | 176 |
|
---|
[4740] | 177 | // }
|
---|
| 178 | // return false;
|
---|
| 179 | //}
|
---|
| 180 | //public bool DeleteUser(Guid id)
|
---|
| 181 | //{
|
---|
[4588] | 182 |
|
---|
[4740] | 183 | // User user = GetUser(id);
|
---|
| 184 | // if (user != null)
|
---|
| 185 | // {
|
---|
[4647] | 186 |
|
---|
[4740] | 187 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 188 | // {
|
---|
| 189 | // try
|
---|
| 190 | // {
|
---|
| 191 | // Application application = GetApplication(user.ApplicationId);
|
---|
| 192 | // if (application == null)
|
---|
| 193 | // {
|
---|
| 194 | // return false;
|
---|
| 195 | // }
|
---|
[4647] | 196 |
|
---|
[4740] | 197 | // int? tablesToDeleteFrom = 99;
|
---|
| 198 | // int? numTablesDeletedFrom = null;
|
---|
| 199 | // db.aspnet_Users_DeleteUser(application.ApplicationName, user.UserName, tablesToDeleteFrom, ref numTablesDeletedFrom);
|
---|
[4647] | 200 |
|
---|
[4740] | 201 | // if (numTablesDeletedFrom != null)
|
---|
| 202 | // {
|
---|
| 203 | // return true;
|
---|
| 204 | // }
|
---|
| 205 | // else
|
---|
| 206 | // {
|
---|
| 207 | // return false;
|
---|
| 208 | // }
|
---|
| 209 | // }
|
---|
| 210 | // catch (Exception ex)
|
---|
| 211 | // {
|
---|
| 212 | // Debug.WriteLine(ex.InnerException);
|
---|
| 213 | // return false;
|
---|
| 214 | // }
|
---|
| 215 | // }
|
---|
| 216 | // }
|
---|
| 217 | // return false;
|
---|
| 218 | //}
|
---|
[4647] | 219 |
|
---|
[4740] | 220 | //public bool UpdateUser(User user)
|
---|
| 221 | //{
|
---|
[4647] | 222 |
|
---|
[4740] | 223 | // if (user != null)
|
---|
| 224 | // {
|
---|
[4647] | 225 |
|
---|
[4740] | 226 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 227 | // {
|
---|
| 228 | // try
|
---|
| 229 | // {
|
---|
| 230 | // if (user.Membership == null)
|
---|
| 231 | // {
|
---|
| 232 | // return false;
|
---|
| 233 | // }
|
---|
[4647] | 234 |
|
---|
[4740] | 235 | // Table<aspnet_User> UserTable = db.GetTable<aspnet_User>();
|
---|
[4647] | 236 |
|
---|
[4740] | 237 | // var User = from item in UserTable
|
---|
| 238 | // where item.UserId == user.UserId
|
---|
| 239 | // select item;
|
---|
| 240 | // aspnet_User eUser = ((aspnet_User)User.Single());
|
---|
[4647] | 241 |
|
---|
| 242 |
|
---|
[4740] | 243 | // Table<aspnet_Membership> MembershipTable = db.GetTable<aspnet_Membership>();
|
---|
[4647] | 244 |
|
---|
[4740] | 245 | // var Membership = from item in MembershipTable
|
---|
| 246 | // where item.UserId == user.UserId
|
---|
| 247 | // select item;
|
---|
[4647] | 248 |
|
---|
[4740] | 249 | // aspnet_Membership eMembership = ((aspnet_Membership)Membership.Single());
|
---|
[4647] | 250 |
|
---|
[4740] | 251 | // Convert.ToEntity(user, eUser);
|
---|
[4647] | 252 |
|
---|
[4740] | 253 | // Convert.ToEntity(user.Membership, eMembership);
|
---|
| 254 | // if (eUser == null)
|
---|
| 255 | // {
|
---|
| 256 | // return false;
|
---|
| 257 | // }
|
---|
| 258 | // if (eMembership == null)
|
---|
| 259 | // {
|
---|
| 260 | // return false;
|
---|
| 261 | // }
|
---|
| 262 | // db.SubmitChanges();
|
---|
| 263 | // }
|
---|
| 264 | // catch (Exception ex)
|
---|
| 265 | // {
|
---|
| 266 | // Debug.WriteLine(ex.InnerException);
|
---|
| 267 | // return false;
|
---|
| 268 | // }
|
---|
| 269 | // }
|
---|
| 270 | // } return false;
|
---|
| 271 | //}
|
---|
[4588] | 272 |
|
---|
[4740] | 273 | //#endregion
|
---|
[4588] | 274 |
|
---|
[4740] | 275 | //#region Role
|
---|
[4588] | 276 |
|
---|
[4740] | 277 | //public Role GetRole(Guid id)
|
---|
| 278 | //{
|
---|
| 279 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 280 | // {
|
---|
| 281 | // try
|
---|
| 282 | // {
|
---|
| 283 | // Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
|
---|
[4588] | 284 |
|
---|
[4740] | 285 | // var Role = from item in RoleTable
|
---|
| 286 | // where item.RoleId == id
|
---|
| 287 | // select item;
|
---|
| 288 | // return Convert.ToDataTransfer((aspnet_Role)Role.Single());
|
---|
| 289 | // }
|
---|
| 290 | // catch (Exception ex)
|
---|
| 291 | // {
|
---|
| 292 | // Debug.WriteLine(ex.InnerException);
|
---|
| 293 | // return null;
|
---|
| 294 | // }
|
---|
| 295 | // }
|
---|
| 296 | //}
|
---|
[4588] | 297 |
|
---|
[4740] | 298 | //public Role GetRole(Guid applicationId, string roleName)
|
---|
| 299 | //{
|
---|
| 300 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 301 | // {
|
---|
| 302 | // try
|
---|
| 303 | // {
|
---|
| 304 | // Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
|
---|
[4647] | 305 |
|
---|
[4740] | 306 | // var Role = from item in RoleTable
|
---|
| 307 | // where item.RoleName == roleName && item.ApplicationId == applicationId
|
---|
| 308 | // select item;
|
---|
| 309 | // return Convert.ToDataTransfer((aspnet_Role)Role.Single());
|
---|
| 310 | // }
|
---|
| 311 | // catch (Exception ex)
|
---|
| 312 | // {
|
---|
| 313 | // Debug.WriteLine(ex.InnerException);
|
---|
| 314 | // return null;
|
---|
| 315 | // }
|
---|
| 316 | // }
|
---|
| 317 | //}
|
---|
[4647] | 318 |
|
---|
[4740] | 319 | //public bool RoleExists(Guid roleId)
|
---|
| 320 | //{
|
---|
| 321 | // if (roleId != null)
|
---|
| 322 | // {
|
---|
| 323 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 324 | // {
|
---|
| 325 | // try
|
---|
| 326 | // {
|
---|
| 327 | // Role role = GetRole(roleId);
|
---|
| 328 | // if (role == null)
|
---|
| 329 | // {
|
---|
| 330 | // return false;
|
---|
| 331 | // }
|
---|
| 332 | // Application application = GetApplication(role.ApplicationId);
|
---|
| 333 | // if (application == null)
|
---|
| 334 | // {
|
---|
| 335 | // return false;
|
---|
| 336 | // }
|
---|
[4647] | 337 |
|
---|
[4740] | 338 | // int result = db.aspnet_Roles_RoleExists(application.ApplicationName, role.RoleName);
|
---|
[4647] | 339 |
|
---|
[4740] | 340 | // return (result == 0);
|
---|
| 341 | // }
|
---|
| 342 | // catch (Exception ex)
|
---|
| 343 | // {
|
---|
| 344 | // Debug.Write(ex.InnerException);
|
---|
| 345 | // return false;
|
---|
| 346 | // }
|
---|
| 347 | // }
|
---|
[4647] | 348 |
|
---|
[4740] | 349 | // } return false;
|
---|
| 350 | //}
|
---|
[4647] | 351 |
|
---|
[4740] | 352 | //public IEnumerable<Role> GetRoles(Guid applicationId)
|
---|
| 353 | //{
|
---|
| 354 | // List<Role> RoleList = new List<Role>();
|
---|
[4588] | 355 |
|
---|
[4740] | 356 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 357 | // {
|
---|
| 358 | // try
|
---|
| 359 | // {
|
---|
| 360 | // // db.aspnet_Roles_GetAllRoles(applicationName);
|
---|
| 361 | // Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
|
---|
[4590] | 362 |
|
---|
[4740] | 363 | // var Roles = from item in RoleTable
|
---|
| 364 | // where item.ApplicationId == applicationId
|
---|
| 365 | // select item;
|
---|
| 366 | // foreach (var Role in Roles)
|
---|
| 367 | // {
|
---|
| 368 | // RoleList.Add(Convert.ToDataTransfer((aspnet_Role)Role));
|
---|
| 369 | // }
|
---|
| 370 | // }
|
---|
| 371 | // catch (Exception ex)
|
---|
| 372 | // {
|
---|
| 373 | // Debug.WriteLine(ex.InnerException);
|
---|
| 374 | // return new List<Role>();
|
---|
| 375 | // }
|
---|
| 376 | // }
|
---|
[4588] | 377 |
|
---|
[4740] | 378 | // return RoleList;
|
---|
| 379 | //}
|
---|
[4647] | 380 |
|
---|
[4740] | 381 | //public bool InsertRole(Role role)
|
---|
| 382 | //{
|
---|
| 383 | // if (role != null)
|
---|
| 384 | // {
|
---|
| 385 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 386 | // {
|
---|
| 387 | // try
|
---|
| 388 | // {
|
---|
| 389 | // Application application = GetApplication(role.ApplicationId);
|
---|
| 390 | // if (application == null)
|
---|
| 391 | // {
|
---|
| 392 | // return false;
|
---|
| 393 | // }
|
---|
| 394 | // int result = db.aspnet_Roles_CreateRole(application.ApplicationName, role.RoleName);
|
---|
[4647] | 395 |
|
---|
[4740] | 396 | // return (result == 0); // checken, welchen rückgabewert (in db, procedure)
|
---|
[4647] | 397 |
|
---|
[4740] | 398 | // }
|
---|
| 399 | // catch (Exception ex)
|
---|
| 400 | // {
|
---|
| 401 | // Debug.WriteLine(ex.InnerException);
|
---|
| 402 | // return false;
|
---|
| 403 | // }
|
---|
| 404 | // }
|
---|
[4647] | 405 |
|
---|
[4740] | 406 | // }
|
---|
| 407 | // return false;
|
---|
| 408 | //}
|
---|
| 409 | //public bool UpdateRole(Role role)
|
---|
| 410 | //{
|
---|
[4647] | 411 |
|
---|
[4740] | 412 | // if (role != null)
|
---|
| 413 | // {
|
---|
[4647] | 414 |
|
---|
[4740] | 415 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 416 | // {
|
---|
| 417 | // try
|
---|
| 418 | // {
|
---|
[4647] | 419 |
|
---|
[4740] | 420 | // Table<aspnet_Role> RoleTable = db.GetTable<aspnet_Role>();
|
---|
[4647] | 421 |
|
---|
[4740] | 422 | // var Role = from item in RoleTable
|
---|
| 423 | // where item.RoleId == role.RoleId
|
---|
| 424 | // select item;
|
---|
| 425 | // aspnet_Role eRole = ((aspnet_Role)Role.Single());
|
---|
[4647] | 426 |
|
---|
| 427 |
|
---|
[4740] | 428 | // Convert.ToEntity(role, eRole);
|
---|
[4647] | 429 |
|
---|
[4740] | 430 | // if (eRole != null)
|
---|
| 431 | // {
|
---|
| 432 | // db.SubmitChanges();
|
---|
| 433 | // }
|
---|
| 434 | // else
|
---|
| 435 | // {
|
---|
| 436 | // return false;
|
---|
| 437 | // }
|
---|
| 438 | // }
|
---|
| 439 | // catch (Exception ex)
|
---|
| 440 | // {
|
---|
| 441 | // Debug.WriteLine(ex.InnerException);
|
---|
| 442 | // return false;
|
---|
| 443 | // }
|
---|
| 444 | // }
|
---|
| 445 | // } return false;
|
---|
| 446 | //}
|
---|
[4647] | 447 |
|
---|
[4740] | 448 | //public bool DeleteRole(Guid id)
|
---|
| 449 | //{
|
---|
| 450 | // if (id != null)
|
---|
| 451 | // {
|
---|
| 452 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 453 | // {
|
---|
| 454 | // try
|
---|
| 455 | // {
|
---|
| 456 | // Role role = GetRole(id);
|
---|
[4647] | 457 |
|
---|
[4740] | 458 | // bool deleteOnlyIfRoleIsEmpty = false;
|
---|
| 459 | // if (role == null)
|
---|
| 460 | // {
|
---|
| 461 | // return false;
|
---|
| 462 | // }
|
---|
| 463 | // Application application = GetApplication(role.ApplicationId);
|
---|
| 464 | // if (application == null)
|
---|
| 465 | // {
|
---|
| 466 | // return false;
|
---|
| 467 | // }
|
---|
| 468 | // db.aspnet_Roles_DeleteRole(application.ApplicationName, role.RoleName, deleteOnlyIfRoleIsEmpty);
|
---|
[4647] | 469 |
|
---|
| 470 |
|
---|
| 471 |
|
---|
[4740] | 472 | // return true;
|
---|
| 473 | // }
|
---|
| 474 | // catch (Exception ex)
|
---|
| 475 | // {
|
---|
| 476 | // Debug.WriteLine(ex.InnerException);
|
---|
| 477 | // return false;
|
---|
| 478 | // }
|
---|
| 479 | // }
|
---|
[4647] | 480 |
|
---|
[4740] | 481 | // }
|
---|
| 482 | // return false;
|
---|
| 483 | //}
|
---|
[4647] | 484 |
|
---|
[4740] | 485 | //public bool IsUserInRole(Guid roleId, Guid userId)
|
---|
| 486 | //{
|
---|
| 487 | // if (roleId != null && userId != null)
|
---|
| 488 | // {
|
---|
| 489 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 490 | // {
|
---|
[4647] | 491 |
|
---|
[4740] | 492 | // try
|
---|
| 493 | // {
|
---|
| 494 | // User user = GetUser(userId);
|
---|
| 495 | // if (user == null) { return false; }
|
---|
[4647] | 496 |
|
---|
[4740] | 497 | // Application application = GetApplication(user.ApplicationId);
|
---|
| 498 | // if (application == null) { return false; }
|
---|
[4647] | 499 |
|
---|
[4740] | 500 | // Role role = GetRole(roleId);
|
---|
| 501 | // if (role == null) { return false; }
|
---|
[4647] | 502 |
|
---|
[4740] | 503 | // int result = db.aspnet_UsersInRoles_IsUserInRole(application.ApplicationName, user.UserName, role.RoleName);
|
---|
[4647] | 504 |
|
---|
[4740] | 505 | // return (result == 0);
|
---|
| 506 | // }
|
---|
| 507 | // catch (Exception ex)
|
---|
| 508 | // {
|
---|
| 509 | // Debug.WriteLine(ex.InnerException);
|
---|
| 510 | // return false;
|
---|
[4647] | 511 |
|
---|
[4740] | 512 | // }
|
---|
[4647] | 513 |
|
---|
[4740] | 514 | // }
|
---|
[4647] | 515 |
|
---|
[4740] | 516 | // } return false;
|
---|
| 517 | //}
|
---|
[4647] | 518 |
|
---|
[4740] | 519 | //public bool AddUserToRole(Guid roleId, Guid userId)
|
---|
| 520 | //{
|
---|
| 521 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 522 | // {
|
---|
| 523 | // try
|
---|
| 524 | // {
|
---|
| 525 | // Role role = GetRole(roleId);
|
---|
| 526 | // if (role == null)
|
---|
| 527 | // {
|
---|
| 528 | // return false;
|
---|
| 529 | // }
|
---|
| 530 | // Application application = GetApplication(role.ApplicationId);
|
---|
| 531 | // if (application == null)
|
---|
| 532 | // {
|
---|
| 533 | // return false;
|
---|
| 534 | // }
|
---|
| 535 | // User user = GetUser(userId);
|
---|
| 536 | // if (user == null)
|
---|
| 537 | // {
|
---|
| 538 | // return false;
|
---|
| 539 | // }
|
---|
[4647] | 540 |
|
---|
[4740] | 541 | // db.aspnet_UsersInRoles_AddUsersToRoles(application.ApplicationName, user.UserName, role.RoleName,DateTime.Now);
|
---|
| 542 | // return true;
|
---|
| 543 | // }
|
---|
| 544 | // catch (Exception ex)
|
---|
| 545 | // {
|
---|
| 546 | // Debug.WriteLine(ex.InnerException);
|
---|
| 547 | // return false;
|
---|
| 548 | // }
|
---|
| 549 | // }
|
---|
[4647] | 550 |
|
---|
[4740] | 551 | //}
|
---|
| 552 | //public bool RemoveUserFromRole(Guid roleId, Guid userId)
|
---|
| 553 | //{
|
---|
| 554 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 555 | // {
|
---|
| 556 | // try
|
---|
| 557 | // {
|
---|
| 558 | // Role role = GetRole(roleId);
|
---|
| 559 | // if (role == null)
|
---|
| 560 | // {
|
---|
| 561 | // return false;
|
---|
| 562 | // }
|
---|
| 563 | // Application application = GetApplication(role.ApplicationId);
|
---|
| 564 | // if (application == null)
|
---|
| 565 | // {
|
---|
| 566 | // return false;
|
---|
| 567 | // }
|
---|
| 568 | // User user = GetUser(userId);
|
---|
| 569 | // if (user == null)
|
---|
| 570 | // {
|
---|
| 571 | // return false;
|
---|
| 572 | // }
|
---|
[4647] | 573 |
|
---|
[4740] | 574 | // db.aspnet_UsersInRoles_RemoveUsersFromRoles(application.ApplicationName, user.UserName, role.RoleName);
|
---|
| 575 | // return true;
|
---|
[4647] | 576 |
|
---|
[4740] | 577 | // }
|
---|
| 578 | // catch (Exception ex)
|
---|
| 579 | // {
|
---|
| 580 | // Debug.WriteLine(ex.InnerException);
|
---|
| 581 | // return false;
|
---|
| 582 | // }
|
---|
| 583 | // }
|
---|
[4647] | 584 |
|
---|
[4740] | 585 | //}
|
---|
| 586 | //public IEnumerable<Role> GetRolesForUser(Guid userId)
|
---|
| 587 | //{
|
---|
| 588 | // List<Role> roles = new List<Role>();
|
---|
| 589 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 590 | // {
|
---|
| 591 | // try
|
---|
| 592 | // {
|
---|
| 593 | // User user = GetUser(userId);
|
---|
| 594 | // if (user == null)
|
---|
| 595 | // {
|
---|
| 596 | // return roles;
|
---|
| 597 | // }
|
---|
| 598 | // Application application = GetApplication(user.ApplicationId);
|
---|
| 599 | // if (application == null)
|
---|
| 600 | // {
|
---|
| 601 | // return roles;
|
---|
| 602 | // }
|
---|
[4647] | 603 |
|
---|
| 604 |
|
---|
[4740] | 605 | // ISingleResult<aspnet_UsersInRoles_GetRolesForUserResult> results = db.aspnet_UsersInRoles_GetRolesForUser(application.ApplicationName,user.UserName);
|
---|
| 606 | // foreach (aspnet_UsersInRoles_GetRolesForUserResult userInRole in results)
|
---|
| 607 | // {
|
---|
| 608 | // roles.Add(GetRole(application.ApplicationId,userInRole.RoleName));
|
---|
| 609 | // }
|
---|
| 610 | // }
|
---|
| 611 | // catch (Exception ex)
|
---|
| 612 | // {
|
---|
| 613 | // Debug.WriteLine(ex.InnerException);
|
---|
| 614 | // return new List<Role>();
|
---|
| 615 | // }
|
---|
| 616 | // }
|
---|
[4647] | 617 |
|
---|
[4740] | 618 | // return roles;
|
---|
| 619 | //}
|
---|
[4588] | 620 |
|
---|
[4740] | 621 | //public IEnumerable<User> GetUsersInRole(Guid roleId)
|
---|
| 622 | //{
|
---|
| 623 | // List<User> users = new List<User>();
|
---|
[4647] | 624 |
|
---|
[4740] | 625 | // using(UserManagementDataContext db = new UserManagementDataContext()){
|
---|
| 626 | // try
|
---|
| 627 | // {
|
---|
| 628 | // Role role = GetRole(roleId);
|
---|
[4647] | 629 |
|
---|
[4740] | 630 | // if (role != null)
|
---|
| 631 | // {
|
---|
| 632 | // Application application = GetApplication(role.ApplicationId);
|
---|
[4647] | 633 |
|
---|
[4740] | 634 | // if (application != null)
|
---|
| 635 | // {
|
---|
[4647] | 636 |
|
---|
| 637 |
|
---|
[4740] | 638 | // ISingleResult<aspnet_UsersInRoles_GetUsersInRolesResult> result = db.aspnet_UsersInRoles_GetUsersInRoles(application.ApplicationName, role.RoleName);
|
---|
| 639 | // foreach (aspnet_UsersInRoles_GetUsersInRolesResult usersInRole in result)
|
---|
| 640 | // {
|
---|
| 641 | // users.Add(GetUser(application.ApplicationId,usersInRole.UserName));
|
---|
| 642 | // }
|
---|
| 643 | // }
|
---|
| 644 | // }
|
---|
| 645 | // }
|
---|
| 646 | // catch (Exception ex)
|
---|
| 647 | // {
|
---|
| 648 | // Debug.WriteLine(ex.InnerException);
|
---|
| 649 | // return new List<User>();
|
---|
| 650 | // }
|
---|
| 651 | // }
|
---|
[4647] | 652 |
|
---|
[4740] | 653 | // return users;
|
---|
| 654 | //}
|
---|
[4647] | 655 |
|
---|
[4740] | 656 | //#endregion
|
---|
[4647] | 657 |
|
---|
[4740] | 658 | //#region Application
|
---|
[4647] | 659 |
|
---|
[4740] | 660 | //public Application InsertApplication(Application application)
|
---|
| 661 | //{
|
---|
| 662 | // if (application != null)
|
---|
| 663 | // {
|
---|
| 664 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 665 | // {
|
---|
| 666 | // try
|
---|
| 667 | // {
|
---|
| 668 | // Guid? applicationId = null;
|
---|
| 669 | // int result = db.aspnet_Applications_CreateApplication(application.ApplicationName, ref applicationId);
|
---|
| 670 | // Console.WriteLine("result=" + result);
|
---|
| 671 | // if (applicationId != null)
|
---|
| 672 | // {
|
---|
| 673 | // application.ApplicationId = (Guid)applicationId;
|
---|
| 674 | // return application;
|
---|
| 675 | // }
|
---|
| 676 | // else
|
---|
| 677 | // {
|
---|
| 678 | // return null;
|
---|
| 679 | // }
|
---|
| 680 | // }
|
---|
| 681 | // catch (Exception ex)
|
---|
| 682 | // {
|
---|
| 683 | // Debug.WriteLine(ex.InnerException);
|
---|
| 684 | // return null;
|
---|
| 685 | // }
|
---|
| 686 | // }
|
---|
[4647] | 687 |
|
---|
[4740] | 688 | // }
|
---|
| 689 | // return null;
|
---|
| 690 | //}
|
---|
[4647] | 691 |
|
---|
[4740] | 692 | //public bool DeleteApplication(Application application)
|
---|
| 693 | //{
|
---|
| 694 | // return false;
|
---|
| 695 | //}
|
---|
[4647] | 696 |
|
---|
[4740] | 697 | //public Application GetApplication(Guid id)
|
---|
| 698 | //{
|
---|
| 699 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 700 | // {
|
---|
| 701 | // try
|
---|
| 702 | // {
|
---|
| 703 | // Table<aspnet_Application> ApplicationTable = db.GetTable<aspnet_Application>();
|
---|
[4647] | 704 |
|
---|
[4740] | 705 | // var Application = from item in ApplicationTable
|
---|
| 706 | // where item.ApplicationId == id
|
---|
| 707 | // select item;
|
---|
| 708 | // return Convert.ToDataTransfer((aspnet_Application)Application.Single());
|
---|
| 709 | // }
|
---|
| 710 | // catch (Exception ex)
|
---|
| 711 | // {
|
---|
| 712 | // Debug.WriteLine(ex.InnerException);
|
---|
| 713 | // return null;
|
---|
| 714 | // }
|
---|
| 715 | // }
|
---|
| 716 | //}
|
---|
[4647] | 717 |
|
---|
[4740] | 718 | //public IEnumerable<DataTransfer.Application> GetApplications()
|
---|
| 719 | //{
|
---|
| 720 | // List<DataTransfer.Application> ApplicationList = new List<DataTransfer.Application>();
|
---|
| 721 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 722 | // {
|
---|
| 723 | // try
|
---|
| 724 | // {
|
---|
| 725 | // Table<aspnet_Application> ApplicationTable = db.GetTable<aspnet_Application>();
|
---|
| 726 | // var Applications = from item in ApplicationTable
|
---|
| 727 | // select item;
|
---|
| 728 | // foreach (var eApplication in Applications)
|
---|
| 729 | // {
|
---|
[4726] | 730 |
|
---|
[4740] | 731 | // Application application = Convert.ToDataTransfer(eApplication);
|
---|
[4726] | 732 |
|
---|
[4740] | 733 | // if (application == null) { return null; }
|
---|
[4726] | 734 |
|
---|
| 735 |
|
---|
[4740] | 736 | // ApplicationList.Add(application);
|
---|
| 737 | // }
|
---|
| 738 | // }
|
---|
| 739 | // catch (Exception ex)
|
---|
| 740 | // {
|
---|
| 741 | // Debug.WriteLine(ex.InnerException);
|
---|
| 742 | // return new List<Application>();
|
---|
| 743 | // }
|
---|
| 744 | // }
|
---|
[4726] | 745 |
|
---|
[4740] | 746 | // return ApplicationList;
|
---|
| 747 | //}
|
---|
[4726] | 748 |
|
---|
| 749 |
|
---|
| 750 |
|
---|
[4740] | 751 | //#endregion
|
---|
[4647] | 752 |
|
---|
[4740] | 753 | //#region Membership
|
---|
[4647] | 754 |
|
---|
[4740] | 755 | //public Membership InsertMembership(Membership membership)
|
---|
| 756 | //{
|
---|
[4647] | 757 |
|
---|
[4740] | 758 | // if (membership != null)
|
---|
| 759 | // {
|
---|
| 760 | // using (UserManagementDataContext db = new UserManagementDataContext())
|
---|
| 761 | // {
|
---|
| 762 | // try
|
---|
| 763 | // {
|
---|
| 764 | // Application application = GetApplication(membership.ApplicationId);
|
---|
| 765 | // if (application == null) { return null; }
|
---|
[4647] | 766 |
|
---|
[4740] | 767 | // }
|
---|
| 768 | // catch (Exception ex)
|
---|
| 769 | // {
|
---|
| 770 | // Debug.WriteLine(ex.InnerException);
|
---|
| 771 | // return null;
|
---|
| 772 | // }
|
---|
| 773 | // }
|
---|
| 774 | // }
|
---|
| 775 | // return null;
|
---|
| 776 | //}
|
---|
[4647] | 777 |
|
---|
[4740] | 778 | //#endregion
|
---|
[4584] | 779 | }
|
---|
| 780 | }
|
---|
[4590] | 781 |
|
---|