public UserManager() { UCrud = new UserCrud(); RCrud = new RoleCrud(); PasswordCrud = new UserPasswordCrud(); VCrud = new ViewCrud(); TCrud = new TerminalCrud(); }
/// <summary> /// Refreshs the entity instance from the database. /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="appSettings"> /// Entity to refresh (must be in database). /// </param> public void Refresh(IUserContext userContext, ref VahapYigit.Test.Models.Role entity) { using (var et = new ExecutionTracerService()) using (var db = new RoleCrud(userContext)) { db.Refresh(ref entity); } }
/// <summary> /// Gets an entity given its unique ID. /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="id"> /// Unique ID. /// </param> /// /// <returns> /// The entity. /// </returns> public VahapYigit.Test.Models.Role GetById(IUserContext userContext, long id) { using (var et = new ExecutionTracerService()) using (var db = new RoleCrud(userContext)) { return(db.GetById(id)); } }
/// <summary> /// Deletes the entity given its unique ID. /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="id"> /// Unique ID. /// </param> /// /// <returns> /// The number of affected rows. /// </returns> public int Delete(IUserContext userContext, long id) { using (var et = new ExecutionTracerService()) using (var db = new RoleCrud(userContext)) { return(db.Delete(id)); } }
/// <summary> /// Loads the UserRole entities associated to the instances (entity.UserRole collection property). /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="entities"> /// The target entity collection. /// </param> public void LoadUserRoleCollection(IUserContext userContext, TCollection <VahapYigit.Test.Models.Role> entities) { using (var et = new ExecutionTracerService()) using (var db = new RoleCrud(userContext)) { db.LoadUserRoleCollection(entities); } }
/// <summary> /// Deletes the entity from the database. /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="entity"> /// Entity to delete. /// </param> /// /// <returns> /// The number of affected rows. /// </returns> public int Delete(IUserContext userContext, VahapYigit.Test.Models.Role entity) { using (var et = new ExecutionTracerService()) using (var db = new RoleCrud(userContext)) { return(db.Delete(entity)); } }
/// <summary> /// Saves (or updates) the entity in the database. /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="entity"> /// Entity to save or update. /// </param> /// /// <param name="options"> /// Optional options. /// </param> /// /// <returns> /// The number of affected rows. /// </returns> public int Save(IUserContext userContext, ref VahapYigit.Test.Models.Role entity, SaveOptions options = null) { using (var et = new ExecutionTracerService(tag: entity.State.ToString())) using (var db = new RoleCrud(userContext)) { return(db.Save(ref entity, options)); } }
/// <summary> /// Indicates whether the search returns at least 1 entity. /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="options"> /// Optional search options. If not defined, all records are returned. /// </param> /// /// <returns> /// True if the search returns at least 1 entity; otherwise, false. /// </returns> public bool HasResult(IUserContext userContext, SearchOptions options = null) { using (var et = new ExecutionTracerService()) using (var db = new RoleCrud(userContext)) { return(db.HasResult(options)); } }
/// <summary> /// Gets entities with search options. /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="options"> /// Optional options, filters, orderby, paging, etc. /// </param> /// /// <returns> /// A collection of entities. /// </returns> public TCollection <VahapYigit.Test.Models.Role> Search(IUserContext userContext, ref SearchOptions options) { using (var et = new ExecutionTracerService()) using (var db = new RoleCrud(userContext)) { return(db.Search(ref options)); } }
/// <summary> /// Gets an entity given its unique CodeRef value. /// </summary> /// /// <param name="userContext"> /// User context. /// </param> /// /// <param name="codeRef"> /// Unique CodeRef value. /// </param> /// /// <returns> /// The entity. /// </returns> public VahapYigit.Test.Models.Role GetByCodeRef(VahapYigit.Test.Core.IUserContext userContext, string codeRef) { using (var et = new ExecutionTracerService()) using (var db = new RoleCrud(userContext)) { return(db.GetByCodeRef(codeRef)); } }
public bool IsRegistered(IUserContext userContext, out User user) { bool bIsRegistered = false; user = null; using (var et = new ExecutionTracerService()) using (var userCrud = new UserCrud(userContext)) using (var userRoleCrud = new UserRoleCrud(userContext)) using (var roleCrud = new RoleCrud(userContext)) { var options = new SearchOptions { MaxRecords = 1 }; // Note about the the first parameter (orGroup) -> different values -> OR operator // Thus userContext.Identifier can contain either the Username or the email address (Unique constraint on these values) options.Filters.Add(0, User.ColumnNames.Username, FilterOperator.Equals, userContext.Identifier); options.Filters.Add(1, User.ColumnNames.Email, FilterOperator.Equals, userContext.Identifier); var users = userCrud.Search(ref options); if (users.Count == 1) { user = users.First(); if (user.Password == userContext.Password) // because of French_CI_AI collation at SQL Server side (Case Insensitive, Accent Insensitive) { bIsRegistered = true; userCrud.LoadUserRoleCollection(ref user); user.UserRoleCollection.ForEach((userRole) => { userRoleCrud.LoadRole(ref userRole); }); user.LastConnectionDate = DateTime.Now; userCrud.Save(ref user); } } } if (!bIsRegistered) { user = null; } return(bIsRegistered); }
public bool Create(IUserContext userContext, ref User user, out IList <TranslationEnum> errors) { bool withError = false; errors = new List <TranslationEnum>(); using (var userCrud = new UserCrud(userContext)) using (var roleCrud = new RoleCrud(userContext)) { // NOTE: if you have a compilation error on 'Role.CodeRefs.Member' // 1. Change Role.CodeRefs.Member by "" // 2. Add the [CodeRef = Member, Name = Member] entry in the 'Role' table // 3. Compile the solution and execute LayerCake Generator // 4. Then change back "" to Role.CodeRefs.Member var memberRole = roleCrud.GetByCodeRef(Role.CodeRefs.Member); if (user.UserRoleCollection.Count(l => l.IdRole == memberRole.Id) == 0) { user.UserRoleCollection.Add(new UserRole { IdUser = user.Id, IdRole = memberRole.Id }); } user.RegistrationDate = DateTime.Now; try { userCrud.Save(ref user, new SaveOptions { SaveChildren = true }); Task.WaitAll(SendMailOnUserCreatedAsync(user)); // cannot use await because of ref/out parameters } catch (EntityValidationException evx) { withError = true; errors = evx.Translations; } catch (System.Net.Mail.SmtpFailedRecipientException) // Cannot deliver the mail (bad email address?) { // NOTE: if you have a compilation error on 'TranslationEnum.CustomExceptionSmtpBadRecipient' // 1. Comment the line // 2. Add the 'CustomExceptionSmtpBadRecipient' entry in the 'Translation' table // 3. Compile the solution // 4. Execute LayerCake Generator Process (Menu > Extensions > Generate Translations) // 5. Close LayerCake Generator // 6. Then uncomment the line and recompile withError = true; errors.Add(TranslationEnum.CustomExceptionSmtpBadRecipient); } catch { withError = true; throw; } finally { if (withError || errors.Count != 0) { if (user.IsInDb) { userCrud.Delete(user); // When the mail has not been delivered... (bad email address?) } } } } return(!withError && errors.Count == 0); }
public RoleManager() { CrudFactory = new RoleCrud(); VCrud = new ViewCrud(); VLCrud = new ValueListCrud(); }