Exemplo n.º 1
0
        public async Task <IResultModel> Add(ModuleAddModel model)
        {
            var entity = _mapper.Map <ModuleEntity>(model);
            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
        public async Task <IActionResult> Create(Module module)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await moduleRepository.AddAsync(module);

                    await moduleRepository.SaveChangesAsync();

                    ViewBag.SuccessMsg = "Module Created Successfully";

                    ModelState.Clear();

                    return(RedirectToAction("Details", new { id = module.ModuleID }));
                }
                return(View(module));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Create(Smartplayer.Authorization.WebApi.DTO.Module.Input.Module module)
        {
            var response = await _moduleRepository.AddAsync(new Module()
            {
                ClubId     = module.ClubId,
                MACAddress = module.MACAddress,
                Name       = module.Name
            });

            return(Ok(true));
        }
Exemplo n.º 4
0
        public async Task <IResultModel> Sync()
        {
            if (!_options.RefreshModuleOrPermission)
            {
                return(ResultModel.Success());
            }

            var modules = _moduleCollection.Select(m => new ModuleEntity
            {
                Number  = m.Id,
                Code    = m.Code,
                Name    = m.Name,
                Icon    = m.Icon,
                Version = m.Version,
                Remarks = m.Description
            });

            _logger.LogDebug("Sync Module Info");

            using (var uow = _dbContext.NewUnitOfWork())
            {
                foreach (var module in modules)
                {
                    if (!await _repository.Exists(module, uow))
                    {
                        if (!await _repository.AddAsync(module))
                        {
                            uow.Rollback();
                            return(ResultModel.Failed());
                        }
                    }
                    else
                    {
                        if (!await _repository.UpdateByCode(module))
                        {
                            uow.Rollback();
                            return(ResultModel.Failed());
                        }
                    }
                }

                uow.Commit();
            }

            return(ResultModel.Success());
        }
Exemplo n.º 5
0
        public async Task <ModuleModel> Create(ModuleModel module)
        {
            var isModuleExists = await _moduleRepository.IsModuleExists(ObjectMapper.Mapper.Map <Module>(module));

            if (isModuleExists)
            {
                throw new ApplicationException(
                          $"Module combination already exists. Name: {module.Name}, Code: {module.Code}, Module Type: {module.ModuleTypeId}, Application: {module.ApplicationId}");
            }

            var newModule = await _moduleRepository.AddAsync(ObjectMapper.Mapper.Map <Module>(module));

            _logger.LogInformationExtension(
                $"Module is successfully created. Module Id: {module.ModuleId}, Name: {module.Name}");

            return(ObjectMapper.Mapper.Map <ModuleModel>(newModule));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> SaveModule([FromBody] ModuleIn moduleIn)
        {
            try
            {
                var module = await _moduleRepository.AddAsync(new Persistance.Models.Module()
                {
                    MACAddress = moduleIn.MACAddress, ClubId = moduleIn.ClubId
                });

                if (module != null)
                {
                    var result = _mapper.Map <ModuleOut>(module);
                    return(Ok(result));
                }
                return(BadRequest());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 7
0
        public async Task <IResultModel> Sync()
        {
            using var uow = _dbContext.NewUnitOfWork();

            var modules = _moduleCollection.Select(m => new ModuleEntity
            {
                Number  = m.Id,
                Name    = m.Name,
                Code    = m.Code,
                Icon    = m.Icon,
                Version = m.Version,
                Remarks = m.Description
            });

            _logger.LogInformation("开始:同步模块信息");

            foreach (var module in modules)
            {
                if (!await _repository.Exists(module, uow))
                {
                    if (!await _repository.AddAsync(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
                else
                {
                    if (!await _repository.UpdateByCode(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
            }

            uow.Commit();

            _logger.LogInformation("结束:同步模块信息");

            return(ResultModel.Success());
        }
Exemplo n.º 8
0
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            using var uow = _dbContext.NewUnitOfWork();

            #region ==同步模块信息==

            var modules = _moduleCollection.Select(m => new ModuleEntity
            {
                Number  = m.Id,
                Name    = m.Name,
                Code    = m.Code,
                Icon    = m.Icon,
                Version = m.Version,
                Remarks = m.Description
            });

            _logger.LogDebug("Sync Module Info");

            foreach (var module in modules)
            {
                if (!await _repository.Exists(module, uow))
                {
                    if (!await _repository.AddAsync(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
                else
                {
                    if (!await _repository.UpdateByCode(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
            }

            #endregion

            #region ==同步权限信息=

            if (permissions != null && permissions.Any())
            {
                _logger.LogDebug("Sync Permission Info");

                //先清除已有权限信息
                if (await _permissionRepository.ClearAsync(uow))
                {
                    foreach (var permission in permissions)
                    {
                        if (!await _permissionRepository.AddAsync(permission, uow))
                        {
                            return(ResultModel.Failed("同步失败"));
                        }
                    }

                    //删除所有账户的权限缓存
                    await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_PERMISSIONS);
                }
            }

            #endregion

            uow.Commit();

            return(ResultModel.Success());
        }