コード例 #1
0
        public void CreateIfNotExist(List <CreateCategoryRequest> createCategoryRequests)
        {
            using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
            {
                ICategoryRepository categoryRepository = IoC.Container.Resolve <ICategoryRepository>(uow);
                foreach (CreateCategoryRequest request in createCategoryRequests)
                {
                    try
                    {
                        this.ValiateCreateCategoryRequest(request);
                        Category category = new Category(request.Name, request.Description);
                        categoryRepository.Add(category);
                    }
                    catch (ValidationException exception)
                    {
                        if (exception.HasExceptionKey("inventory.addOrUpdateCategory.validation.nameAlreadyExisted"))
                        {
                            continue;
                        }
                    }
                }

                uow.Commit();
            }
        }
コード例 #2
0
        public void CreateIfNotExist(IList <CreatePermissionRequest> pers)
        {
            using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
            {
                IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow);
                foreach (CreatePermissionRequest perRequest in pers)
                {
                    try
                    {
                        this.ValidateCreatePermissionRequest(perRequest);
                        Permission permission = new Permission(perRequest.Name, perRequest.Key, perRequest.Description);
                        perRepository.Add(permission);
                    }
                    catch (ValidationException ex)
                    {
                        if (ex.HasExceptionKey("security.addPermission.validation.nameAlreadyExist"))
                        {
                            continue;
                        }
                        if (ex.HasExceptionKey("security.addPermission.validation.keyAlreadyExist"))
                        {
                            continue;
                        }
                    }
                }

                uow.Commit();
            }
        }
コード例 #3
0
 public void Delete(Guid id)
 {
     this.ValidateDeleteRequest(id);
     using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
     {
         IUserGroupRepository repository = IoC.Container.Resolve <IUserGroupRepository>(uow);
         repository.Delete(id);
         uow.Commit();
     }
 }
 public void Delete(Guid id)
 {
     ValidateDeleteRequest(id);
     using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IUserGroupRepository repository = IoC.Container.Resolve <IUserGroupRepository>(uow);
         repository.Delete(id.ToString());
         uow.Commit();
     }
 }
コード例 #5
0
 public void Register(RegisterEventSubcriber request)
 {
     this.ValidateRegisterEventSubcriberRequest(request);
     using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
     {
         IEventSubcriberRepository repo      = Common.DI.IoC.Container.Resolve <IEventSubcriberRepository>(uow);
         EventSubcriber            subcriber = new EventSubcriber(request.Key, request.Uri, request.ModuleName);
         repo.Add(subcriber);
         uow.Commit();
     }
 }
 public BaseContent CreatePermission(BaseContent permission)
 {
     CreatePermissionValidation(permission);
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow);
         Permission            per           = new Permission(permission);
         perRepository.Add(per);
         uow.Commit();
         return(per);
     }
 }
コード例 #7
0
 public CreatePermissionResponse Create(CreatePermissionRequest permission)
 {
     this.ValidateCreatePermissionRequest(permission);
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
     {
         IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow);
         Permission            per           = new Permission(permission.Name, permission.Key, permission.Description);
         perRepository.Add(per);
         uow.Commit();
         return(ObjectHelper.Convert <CreatePermissionResponse>(per));
     }
 }
コード例 #8
0
 public DeleteRoleResponse Delete(Guid id)
 {
     ValidationForDeleting(id);
     using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IRoleRepository    repository     = IoC.Container.Resolve <IRoleRepository>(uow);
         DeleteRoleResponse deleteResponse = repository.GetById <DeleteRoleResponse>(id.ToString());
         repository.Delete(id.ToString());
         uow.Commit();
         return(deleteResponse);
     }
 }
コード例 #9
0
 public void Add(IList <Language> languages)
 {
     using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         ILanguageRepository repository = App.Common.DI.IoC.Container.Resolve <ILanguageRepository>();
         foreach (Language item in languages)
         {
             repository.AddIfNotExist(item);
         }
         uow.Commit();
     }
 }
コード例 #10
0
 public DeleteRoleResponse Delete(Guid id)
 {
     this.ValidateDeleteRequest(id);
     using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
     {
         IRoleRepository    repository     = IoC.Container.Resolve <IRoleRepository>(uow);
         DeleteRoleResponse deleteResponse = repository.GetById <DeleteRoleResponse>(id.ToString());
         repository.Delete(id);
         uow.Commit();
         return(deleteResponse);
     }
 }
コード例 #11
0
 public void Create(IList <Role> roles)
 {
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IRoleRepository roleRepository = IoC.Container.Resolve <IRoleRepository>(uow);
         foreach (Role role in roles)
         {
             ValidationForCreating(role, roleRepository);
             roleRepository.Add(role);
         }
         uow.Commit();
     }
 }
コード例 #12
0
 public CreateRoleResponse Create(CreateRoleRequest request)
 {
     this.Validate(request);
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
     {
         IRoleRepository       roleRepository = IoC.Container.Resolve <IRoleRepository>(uow);
         IPermissionRepository permissionRepo = IoC.Container.Resolve <IPermissionRepository>(uow);
         IList <Permission>    permissions    = permissionRepo.GetPermissions(request.Permissions);
         Role role = new Role(request.Name, request.Description, permissions);
         roleRepository.Add(role);
         uow.Commit();
         return(ObjectHelper.Convert <CreateRoleResponse>(role));
     }
 }
コード例 #13
0
        public CreateUserResponse CreateUser(CreateUserRequest request)
        {
            this.ValidateCreateUserRequest(request);
            using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
            {
                User user = new User(request.Email, string.Empty, request.FirstName, request.LastName);

                IUserRepository userRepository = IoC.Container.Resolve <IUserRepository>(uow);
                userRepository.Add(user);
                uow.Commit();

                return(ObjectHelper.Convert <CreateUserResponse>(user));
            }
        }
コード例 #14
0
        public void Create(IList <Role> roles)
        {
            using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
            {
                IRoleRepository roleRepository = IoC.Container.Resolve <IRoleRepository>(uow);
                foreach (Role role in roles)
                {
                    this.ValidateCreateRequest(role, roleRepository);
                    roleRepository.Add(role);
                }

                uow.Commit();
            }
        }
コード例 #15
0
 public CreateUserGroupResponse Create(CreateUserGroupRequest request)
 {
     this.ValidateCreateRequest(request);
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
     {
         IUserGroupRepository  userGroupRepository = IoC.Container.Resolve <IUserGroupRepository>(uow);
         IPermissionRepository permissionRepo      = IoC.Container.Resolve <IPermissionRepository>(uow);
         IList <Permission>    permissions         = permissionRepo.GetPermissions(request.PermissionIds);
         UserGroup             userGroup           = new UserGroup(request.Name, request.Description, permissions);
         userGroupRepository.Add(userGroup);
         uow.Commit();
         return(new CreateUserGroupResponse(userGroup));
     }
 }
コード例 #16
0
 public CreateRoleResponse Create(CreateRoleRequest request)
 {
     Validate(request);
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IRoleRepository       roleRepository = IoC.Container.Resolve <IRoleRepository>(uow);
         IPermissionRepository permissionRepo = IoC.Container.Resolve <IPermissionRepository>(uow);
         IList <Permission>    permissions    = permissionRepo.GetPermissions(request.Permissions);
         Role role = new Role(request.Name, request.Description, permissions);
         roleRepository.Add(role);
         uow.Commit();
     }
     return(new CreateRoleResponse());
 }
 public void CreateIfNotExist(IList <Permission> pers)
 {
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow);
         foreach (Permission per in pers)
         {
             if (perRepository.GetByKey(per.Key) != null)
             {
                 continue;
             }
             perRepository.Add(per);
         }
         uow.Commit();
     }
 }
コード例 #18
0
 public void SignOut(string token)
 {
     using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IUserRepository userRepository = IoC.Container.Resolve <IUserRepository>(uow);
         User            user           = userRepository.GetByToken(token);
         if (user == null)
         {
             return;
         }
         user.Token             = string.Empty;
         user.TokenExpiredAfter = DateTime.UtcNow;
         userRepository.Update(user);
         uow.Commit();
     }
 }
コード例 #19
0
 public void CreateIfNotExist(IList <Role> roles)
 {
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IRoleRepository roleRepository = IoC.Container.Resolve <IRoleRepository>(uow);
         foreach (Role role in roles)
         {
             if (roleRepository.GetByKey(role.Key) != null)
             {
                 continue;
             }
             roleRepository.Add(role);
         }
         uow.Commit();
     }
 }
コード例 #20
0
 public void CreateIfNotExist(IList <User> users)
 {
     if (users == null)
     {
         return;
     }
     using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(new App.Context.AppDbContext(IOMode.Write)))
     {
         IUserRepository userRepository = IoC.Container.Resolve <IUserRepository>(uow);
         foreach (User user in users)
         {
             User existUser = userRepository.GetByEmail(user.Email);
             if (existUser != null)
             {
                 continue;
             }
             userRepository.Add(user);
         }
         uow.Commit();
     }
 }
コード例 #21
0
        public UserSignInResponse SignIn(UserSignInRequest request)
        {
            AuthenticationToken token;
            User user;

            this.ValidateUserLoginRequest(request);
            using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
            {
                IUserRepository userRepository = IoC.Container.Resolve <IUserRepository>(uow);
                token                  = new App.Common.AuthenticationToken(Guid.NewGuid(), DateTimeHelper.GetAuthenticationTokenExpiredUtcDateTime());
                user                   = userRepository.GetByEmail(request.Email);
                user.Token             = token.Value;
                user.TokenExpiredAfter = token.ExpiredAfter;
                userRepository.Update(user);
                uow.Commit();
            }

            UserQuickProfile profile = new UserQuickProfile(user);

            return(new UserSignInResponse(token, profile));
        }