Beispiel #1
0
        public bool CreateRole(RoleInDTO role, Guid userInfoId)
        {
            try
            {
                var roleExists = _roleRepository.FindAll().Any(x => x.Name.ToLower() == role.Name.ToLower());

                if (roleExists)
                {
                    return(false);
                }

                var newRole = new Role();
                newRole.Name        = role.Name;
                newRole.Description = role.Description;
                newRole.Status      = role.Status;
                newRole.CreatedOn   = Localization.GetUTCDateNow();
                newRole.CreatedBy   = userInfoId;
                newRole.ModifiedBy  = userInfoId;
                newRole.ModifiedOn  = Localization.GetUTCDateNow();
                newRole.RoleId      = Guid.NewGuid();

                var roleId = _roleRepository.Add(newRole);

                foreach (var mappedRole in role.AccessMappingItems)
                {
                    var roleAccess = new RoleAccess();
                    roleAccess.AccessId   = mappedRole.AccessId;
                    roleAccess.RoleId     = roleId;
                    roleAccess.CreatedBy  = userInfoId;
                    roleAccess.CreatedOn  = Localization.GetUTCDateNow();
                    roleAccess.ModifiedBy = userInfoId;
                    roleAccess.ModifiedOn = Localization.GetUTCDateNow();
                    _roleAccessRepository.Add(roleAccess, true);
                }
            } catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(true);
        }
        public void InsertRoleAccess(RoleAccessViewModel roleAccess)
        {
            if (!Validate(roleAccess.RoleId, roleAccess.ApplicationModulId))
            {
                return;
            }

            RoleAccess entity = new RoleAccess();

            Map(roleAccess, entity);
            _roleAccessRepository.AttachNavigation(entity.ApplicationModul);
            _roleAccessRepository.AttachNavigation(entity.Role);
            _roleAccessRepository.Add(entity);
            _unitOfWork.SaveChanges();
        }
Beispiel #3
0
 public void Add(RoleFeatureAccess roleAccess)
 {
     roleAccessRepository.Add(roleAccess);
 }