示例#1
0
        /// <summary>
        /// Load service from disk.
        /// </summary>
        /// <param name="filePath"></param>
        public void RegisterModule(string filePath)
        {
            string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

            if (baseDirectory.Length == 0)
            {
                baseDirectory = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            }

            string fullPath = Path.Combine(baseDirectory, filePath);

            if (File.Exists(filePath))
            {
                ModuleHeader pluginHeader = ModuleHeaderReader.AppHeader(
                    baseDirectory, fullPath);

                ModuleHeader serviceHeader = ModuleHeaderReader.ServiceHeader(
                    baseDirectory, fullPath);

                if (pluginHeader != null)
                {
                    Module module = new Module();
                    module.enabled = 0;
                    module.type    = (int)ModuleType.App;
                    module.path    = filePath;
                    module.name    = pluginHeader.Name;
                    module.version = pluginHeader.Version;

                    moduleRepository.Add(module);
                }

                if (serviceHeader != null)
                {
                    Module module = new Module();
                    module.enabled = 0;
                    module.type    = (int)ModuleType.Service;
                    module.path    = filePath;
                    module.name    = serviceHeader.Name;
                    module.version = serviceHeader.Version;

                    moduleRepository.Add(module);

                    serviceManager.LoadServices();
                }
            }
            else
            {
                // No such file
            }
        }
        public IHttpActionResult PostModule(ModuleDTO moduleDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (moduleDTO == null)
            {
                return(BadRequest("Missing Values"));
            }

            //if (name == null)
            //    return BadRequest("One or more parameters missing values");

            Module module = Mapper.Map <Module>(moduleDTO);

            ModuleRepo.Add(module);

            try
            {
                ModuleRepo.Save();
                return(Ok(module));
            }
            catch
            {
                return(BadRequest("Failed to add module"));
            }
        }
示例#3
0
        public void Clone(string source, string newSource)
        {
            var netlist = _netlistRepository.Get(source);

            if (netlist == null)
            {
                throw new InvalidOperationException("source netlist does not exists");
            }

            if (source == newSource)
            {
                return;
            }

            _netlistRemover.Remove(newSource);

            netlist.Source = newSource;
            _netlistRepository.Add(netlist);

            foreach (var module in _moduleRepository.GetAll(source))
            {
                module.Netlist = newSource;
                _moduleRepository.Add(module);
            }

            foreach (var instance in _instanceRepository.GetBy(source))
            {
                instance.Netlist = newSource;
                _instanceRepository.Add(instance);
            }
        }
示例#4
0
        public async Task <Message> PostModule([FromBody] ModuleCreation moduleCreation)
        {
            if (moduleCreation == null)
            {
                return(Message.Fail());
            }


            var dbitem = await _moduleRepository.GetSingleAsync(x => x.ModuleName == moduleCreation.ModuleName);

            if (dbitem != null)
            {
                return(Message.Fail().Add("content", "模块名已存在"));
            }

            moduleCreation.ModuleId     = Method.GetGuid32();
            moduleCreation.ModuleStatus = "1";
            // moduleCreation.ModuleOrderNum = await _moduleRepository.OrderNumAsync(moduleCreation.ParentModuleId);

            var newItem = _mapper.Map <TbModule>(moduleCreation);

            _moduleRepository.Add(newItem);

            if (!await _unitOfWork.SaveAsync())
            {
                return(Message.ServerError());
            }
            return(Message.Ok());
        }
        public void WriteConfigToDataBase()
        {
            ClearConfigWhichInDataBse();

            //Module是DataPoint的外键,先添加Module
            foreach (KeyValuePair <int, Module> keyValuePair in _modulesFromConfigFile)
            {
                _moduleRepository.Add(keyValuePair.Value);
            }

            //UnitOfWork机制,调用Commit()才提交到数据库,
            var uwModuleRepository = _moduleRepository as IUnitOfWorkRepository;

            if (uwModuleRepository != null)
            {
                uwModuleRepository.UnitOfWork.Commit();
            }

            //Module是DataPoint的外键,故先设置DataPoint的数据库表中的外键值,否则添加失败
            SetForeignKeyForDataPiont();

            foreach (KeyValuePair <int, DataPoint> keyValuePair in _dataPointsFromConfigFile)
            {
                _dataPointRepository.Add(keyValuePair.Value);
            }

            var uwDataPointReposity = _dataPointRepository as IUnitOfWorkRepository;

            if (uwDataPointReposity != null)
            {
                uwDataPointReposity.UnitOfWork.Commit();
            }
        }
        public ModuleWithModuleGradingDto AddNewModuleWithModuleGrading(ModuleWithModuleGradingDto dto)
        {
            if (CheckIfModuleExists(dto.Module.Name))
            {
                return(null);
            }

            Module module = _mapper.Map <Module>(dto.Module);

            _moduleRepository.Add(module);
            _moduleRepository.Save();

            List <ModuleGrading> moduleGradings = new List <ModuleGrading>();

            for (int i = 0; i < dto.ModuleGradings.Count; i++)
            {
                if (CheckIfModuleGradingExists(dto.ModuleGradings[i].Name, module.Id))
                {
                    continue;
                }

                ModuleGrading moduleGrading = new ModuleGrading
                {
                    Name     = dto.ModuleGradings[i].Name,
                    Weight   = dto.ModuleGradings[i].Weight,
                    ModuleId = module.Id
                };

                moduleGradings.Add(moduleGrading);
                _moduleGradingRepository.Add(moduleGrading);
            }
            _moduleGradingRepository.Save();

            return(GetModuleWithModuleGradingsByModuleId(module.Id));
        }
示例#7
0
        public AddModuleResponse AddModule(AddModuleRequst requst)
        {
            AddModuleResponse response = new AddModuleResponse();

            try
            {
                foreach (Module module in requst.ModulesToAdd)
                {
                    _moduleRepository.Add(module);
                }

                _unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                string message = "添加失败!错误信息:/n" + ex.Message;
                response = new AddModuleResponse()
                {
                    ResponseSucceed = false,
                    Message         = "添加失败"
                };
                LoggingFactory.GetLogger().WriteDebugLogger(message);

                return(response);
            }

            return(response);
        }
示例#8
0
        public async Task <IActionResult> CreateModule([FromBody] SaveModuleResource moduleResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var module = mapper.Map <SaveModuleResource, Module>(moduleResource);

            var existName = await repository.ModuleNameExist(module);

            var existCode = await repository.ModuleCodeExist(module);

            if (existName != null && existCode != null)
            {
                return(Conflict("Module name and code already exist."));
            }
            else if (existName != null)
            {
                return(Conflict("Module name already exists."));
            }
            else if (existCode != null)
            {
                return(Conflict("Module code already exists."));
            }

            repository.Add(module);
            await unitOfWork.CompleteAsync();

            module = await repository.GetModule(module.Id);

            var result = mapper.Map <Module, ModuleResource>(module);

            return(Ok(result));
        }
        public ModuleDTO Add(ModuleDTO moduleDTO)
        {
            var module = moduleDTO.ToModel();

            module.Id      = IdentityGenerator.NewSequentialGuid();
            module.Created = DateTime.UtcNow;

            if (module.Name.IsNullOrBlank())
            {
                throw new DefinedException(UserSystemMessagesResources.Name_Empty);
            }

            if (_Repository.Exists(module))
            {
                throw new DataExistsException(string.Format(UserSystemMessagesResources.Module_Exists_WithValue, module.Name));
            }

            _Repository.Add(module);

            #region 操作日志

            var moduleDto = module.ToDto();

            OperateRecorder.RecordOperation(moduleDto.Id.ToString(),
                                            UserSystemMessagesResources.Add_Module,
                                            moduleDto.GetOperationLog());

            #endregion

            //commit the unit of work
            _Repository.UnitOfWork.Commit();

            return(module.ToDto());
        }
示例#10
0
 /// <summary>
 /// 添加或修改
 /// </summary>
 /// <param name="model"></param>
 public void AddOrModity(Module model)
 {
     if (!string.IsNullOrEmpty(model.Id))
     {
         model.LastUpdateDate = DateTime.Now;
         moduleRepository.Modity(model);
     }
     else
     {
         model.ParentId = string.IsNullOrEmpty(model.ParentId) ? Guid.Empty.ToString() : model.ParentId;
         model.GenerateNewIdentity();
         model.CreateDate     = DateTime.Now;
         model.LastUpdateDate = DateTime.Now;
         moduleRepository.Add(model);
     }
     moduleRepository.SaveChanges();
 }
        public void PortsToUpper_BothLibraryGatesAndNonLibraryGatesInstances_UppercasePortsOnlyForLibraryGatesInstances()
        {
            _netlistRepository.Add(new Netlist(DummyNetlist));
            _moduleRepository.Add(new Module(DummyNetlist, "m1"));
            _moduleRepository.Add(new Module(DummyNetlist, "m2"));
            _instanceRepository.Add(new InstanceBuilder(DummyNetlist, "m1").New("an2", "inst1").Add("a", "w").Build());
            _instanceRepository.Add(new InstanceBuilder(DummyNetlist, "m1").New("some-non-library-gate", "inst2", InstanceType.Module).Add("b", "w").Build());
            _instanceRepository.Add(new InstanceBuilder(DummyNetlist, "m2").New("an2", "inst3").Add("c", "w").Build());

            _target.PortsToUpper(DummyNetlist);

            var instances = _instanceRepository.GetBy(DummyNetlist).ToList();

            Assert.That(instances, Has.Exactly(1).Matches <Instance>(i => i.InstanceName == "inst1" && i.Net[0].Port == "A"));
            Assert.That(instances, Has.Exactly(1).Matches <Instance>(i => i.InstanceName == "inst2" && i.Net[0].Port == "b"));
            Assert.That(instances, Has.Exactly(1).Matches <Instance>(i => i.InstanceName == "inst3" && i.Net[0].Port == "C"));
        }
示例#12
0
        public void Handle(BuildState state)
        {
            state.CurrentModuleName = _parser.GetModuleName(state.CurrentStatementTrimmed);
            var module = new Module(state.NetlistSource, state.CurrentModuleName) {
                Ports = _parser.GetPorts(state.CurrentStatementTrimmed)
            };

            _moduleRepository.Add(module);
        }
示例#13
0
 public IHttpActionResult AddModule(Module module)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     repository.Add(module);
     return(CreatedAtRoute("DefaultApi", new { id = module.ModuleId }, module));
 }
示例#14
0
 public ActionResult Create(Module model)
 {
     if (ModelState.IsValid)
     {
         moduleRepository.Add(model);
         TempData["message"] = string.Format("\"{0}\" đã được lưu thành công", model.Name);
         return(RedirectToIndex());
     }
     return(View(model));
 }
        public void Remove_OneHostModule_RemoveOpenOutputInstances()
        {
            _netlistRepository.Add(new Netlist(DummyNetlist));
            _moduleRepository.Add(new Module(DummyNetlist, "m1"));
            var instanceBuilder = new InstanceBuilder(DummyNetlist, "m1");

            _instanceRepository.Add(instanceBuilder.New("an2", "inst1").Add("a", "w").Build());
            _instanceRepository.Add(instanceBuilder.New("b1", "inst2").Add("a", "w1").Build());
            _instanceRepository.Add(instanceBuilder.New("b1", "inst3").Add("a", "w1").Add("z", null).Build());
            _instanceRepository.Add(instanceBuilder.New("b1", "inst4").Add("a", "w1").Add("z", "").Build());
            _instanceRepository.Add(instanceBuilder.New("b1", "inst5").Add("a", "w1").Add("z", "w2").Build());

            _target.Remove(DummyNetlist, "b1", "z");

            var instances = _instanceRepository.GetBy(DummyNetlist).ToList();

            Assert.That(instances, Has.Count.EqualTo(2));
            Assert.That(instances, Has.Exactly(1).Matches <Instance>(i => i.InstanceName == "inst1"));
            Assert.That(instances, Has.Exactly(1).Matches <Instance>(i => i.InstanceName == "inst5"));
        }
示例#16
0
        public IHttpActionResult PutModule(Module module)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            module = repository.Add(module);

            return(Content(HttpStatusCode.OK, module));
        }
示例#17
0
 public void AddOrUpdate(Module model)
 {
     ChangeModuleCascade(model);
     if (model.Id == Guid.Empty)
     {
         _repository.Add(model);
     }
     else
     {
         _repository.Update(model);
     }
 }
示例#18
0
        public void Clone_SourceNetlistExists_Clone()
        {
            _netlistRepository.Add(new Netlist(DummyNetlist));
            _moduleRepository.Add(new Module(DummyNetlist, "m1"));
            _moduleRepository.Add(new Module(DummyNetlist, "m2"));
            _instanceRepository.Add(new Instance(DummyNetlist, "m1", "an2", "inst1"));
            _instanceRepository.Add(new Instance(DummyNetlist, "m1", "an2", "inst2"));
            _instanceRepository.Add(new Instance(DummyNetlist, "m2", "an3", "inst3"));

            _target.Clone(DummyNetlist, NewDummyNetlist);

            var netlist = _netlistRepository.Get(NewDummyNetlist);

            Assert.That(netlist, Is.Not.Null);

            var modules = _moduleRepository.GetAll(NewDummyNetlist).ToList();

            Assert.That(modules, Has.Count.EqualTo(2));
            Assert.That(modules, Has.Exactly(1).Matches <Module>(m => m.Name == "m1"));
            Assert.That(modules, Has.Exactly(1).Matches <Module>(m => m.Name == "m2"));

            var instances = _instanceRepository.GetBy(NewDummyNetlist).ToList();

            Assert.That(instances, Has.Exactly(1).Matches <Instance>(i => i.InstanceName == "inst1"));
            Assert.That(instances, Has.Exactly(1).Matches <Instance>(i => i.InstanceName == "inst2"));
            Assert.That(instances, Has.Exactly(1).Matches <Instance>(i => i.InstanceName == "inst3"));
        }
示例#19
0
 public IActionResult Edit(rpt_modules modules)
 {
     if (modules.ID > 0)
     {
         moduleRepository.Update(modules, "ModuleName", "FatherModuleID", "ModuleTotalScores", "ModuleAvgScores", "ModuleSort");
     }
     else
     {
         moduleRepository.Add(modules);
     }
     moduleRepository.SaveChanges();
     return(View(modules));
 }
示例#20
0
        /// <summary>
        /// Adds new module to the database
        /// </summary>
        /// <param name="module">Module information to be added. Instance of <see cref="ModuleDomain"/></param>
        /// <returns>ModuleId of the newly created module</returns>
        public int AddModule(ModuleDomain module)
        {
            ValidateModuleModel(module);

            var moduleWithProvidedCode = _moduleRepository.GetByCode(module.Code.SafeTrim());

            if (moduleWithProvidedCode != null)
            {
                throw new NsiArgumentException(MembershipMessages.ModuleCodeAlreadyExists, Common.Enumerations.SeverityEnum.Warning);
            }

            return(_moduleRepository.Add(module));
        }
示例#21
0
        private Module CreateHostModule(string moduleName)
        {
            var hostModule = new Module(DummyNetlist, moduleName)
            {
                Ports = new List <Port> {
                    new Port("w1", PortType.Input), new Port("w2", PortType.Input),
                    new Port("w3", PortType.Input), new Port("w4", PortType.Output), new Port("w5", PortType.Output)
                }
            };

            _moduleRepository.Add(hostModule);

            return(hostModule);
        }
示例#22
0
        public async Task <MessageModel <string> > Post([FromBody] Module module)
        {
            var data = new MessageModel <string>();

            var id = (await _moduleRepository.Add(module));

            data.success = id > 0;
            if (data.success)
            {
                data.response = id.ObjToString();
                data.msg      = "添加成功";
            }

            return(data);
        }
        public void AddOrUpdate(Module vm)
        {
            Module model = new Module();

            vm.CopyTo(model);  //copy一次,防止成员为null的情况
            ChangeModuleCascade(model);
            if (model.Id == 0)
            {
                _repository.Add(model);
            }
            else
            {
                _repository.Update(model);
            }
        }
示例#24
0
        public IHttpActionResult PostModule(ModuleDTO moduleDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Mapper.Initialize(c => c.CreateMap <ModuleDTO, Module>());

            Module module = Mapper.Map <Module>(moduleDTO);

            moduleRepo.Add(module);
            moduleRepo.Save();

            return(CreatedAtRoute("DefaultApi", new { id = module.ID }, module));
        }
示例#25
0
        public bool CreateModule(Module module)
        {
            bool isSuccess = true;

            try
            {
                moduleRepository.Add(module);
                this.SaveRecord();
                ServiceUtil <Module> .WriteActionLog(module.Id, ENUMOperation.CREATE, module);
            }
            catch (Exception ex)
            {
                isSuccess = false;
                logger.Error("Error in creating Module", ex);
            }
            return(isSuccess);
        }
示例#26
0
        public ModuleDTO CreateModule(Guid webid, DataObjects.ModuleDTO moduledto)
        {
            Module parentmodule = null;
            var    module       = Mapper.Map <ModuleDTO, Module>(moduledto);

            module.Web = webRepository.Find(Specification <Web> .Eval(w => w.ID.Equals(moduledto.WebID)));
            if (moduledto.ParentID.HasValue && moduledto.ParentID.Value != Guid.Empty)
            {
                parentmodule = moduleRepository.Find(Specification <Module> .Eval(m => m.ID.Equals(moduledto.ParentID.Value)));
                parentmodule.ChildModule.Add(module);
                moduleRepository.Update(parentmodule);
            }
            else
            {
                moduleRepository.Add(module);
            }
            Context.Commit();
            return(Mapper.Map <Module, ModuleDTO>(module).ToViewModel());
        }
示例#27
0
        public void AddOrUpdate(Module model)
        {
            ChangeModuleCascade(model);
            if (model.Id == Guid.Empty)
            {
                _repository.Add(model);
            }
            else
            {
                //获取旧的的CascadeId
                var CascadeId = _repository.FindSingle(o => o.Id == model.Id).CascadeId;
                //根据CascadeId查询子部门
                var models = _repository.Find(u => u.CascadeId.Contains(CascadeId) && u.Id != model.Id).OrderBy(u => u.CascadeId).ToList();

                _repository.Update(model);

                //更新子部门的CascadeId
                foreach (var a in models)
                {
                    ChangeModuleCascade(a);
                    _repository.Update(a);
                }
            }
        }
示例#28
0
        public IActionResult AddModuleWithAllFeatures([FromBody] Module module)
        {
            var AllFeatures = ReadJson();

            string[] features = null;

            if (module.Name == "Human Resource Management")
            {
                features = AllFeatures.HRMS;
            }
            if (module.Name == "Hospital Management System")
            {
                features = AllFeatures.HIMS;
            }
            if (module.Name == "Payroll Management System")
            {
                features = AllFeatures.Payroll;
            }
            if (module.Name == "Lab Information System")
            {
                features = AllFeatures.Lab;
            }
            if (module.Name == "Inventory")
            {
                features = AllFeatures.Inventory;
            }
            if (module.Name == "eTracker")
            {
                features = AllFeatures.ETracker;
            }
            if (module.Name == "eTrackerMobile")
            {
                features = AllFeatures.ETrackerMobile;
            }
            if (module.Name == "Security Admin")
            {
                features = AllFeatures.Security;
            }


            List <Feature> featureList = new List <Feature>();

            if (features != null)
            {
                foreach (var feature in features)
                {
                    var feat = new Feature
                    {
                        CompanyId = module.CompanyId,
                        ModuleId  = module.ModuleId,
                        Name      = feature
                    };
                    featureList.Add(feat);
                }

                module.Features = featureList;
            }

            module_repo.Add(module);

            return(new OkObjectResult(new { ModuleID = module.ModuleId }));
        }
示例#29
0
        public override void RegisterModule()
        {
            ExecuteFaultHandledOperation(() =>
            {
                ISolutionRepository solutionRepository = _DataRepositoryFactory.GetDataRepository <ISolutionRepository>();
                IModuleRepository moduleRepository     = _DataRepositoryFactory.GetDataRepository <IModuleRepository>();
                IMenuRepository menuRepository         = _DataRepositoryFactory.GetDataRepository <IMenuRepository>();
                IRoleRepository roleRepository         = _DataRepositoryFactory.GetDataRepository <IRoleRepository>();
                IMenuRoleRepository menuRoleRepository = _DataRepositoryFactory.GetDataRepository <IMenuRoleRepository>();

                using (TransactionScope ts = new TransactionScope())
                {
                    //check if module has been installed
                    Module module = moduleRepository.Get().Where(c => c.Name == IFRSCoreModuleDefinition.MODULE_NAME).FirstOrDefault();

                    var register = false;
                    if (module == null)
                    {
                        register = true;
                    }
                    else
                    {
                        register = module.CanUpdate;
                    }

                    if (register)
                    {
                        //check if module category exit
                        Solution solution = solutionRepository.Get().Where(c => c.Name == IFRSCoreModuleDefinition.SOLUTION_NAME).FirstOrDefault();
                        if (solution == null)
                        {
                            //register solution
                            solution = new Solution()
                            {
                                Name      = IFRSCoreModuleDefinition.SOLUTION_NAME,
                                Alias     = IFRSCoreModuleDefinition.SOLUTION_ALIAS,
                                Active    = true,
                                Deleted   = false,
                                CreatedBy = "Auto",
                                CreatedOn = DateTime.Now,
                                UpdatedBy = "Auto",
                                UpdatedOn = DateTime.Now
                            };

                            solution = solutionRepository.Add(solution);
                        }

                        //register module
                        if (module == null)
                        {
                            module = new Module()
                            {
                                Name       = IFRSCoreModuleDefinition.MODULE_NAME,
                                Alias      = IFRSCoreModuleDefinition.MODULE_ALIAS,
                                SolutionId = solution.EntityId,
                                Active     = true,
                                Deleted    = false,
                                CreatedBy  = "Auto",
                                CreatedOn  = DateTime.Now,
                                UpdatedBy  = "Auto",
                                UpdatedOn  = DateTime.Now
                            };

                            module = moduleRepository.Add(module);
                        }

                        //Roles
                        var existingRoles = roleRepository.Get().Where(c => c.SolutionId == solution.SolutionId && c.Type == RoleType.Application).ToList();
                        var updatedRoles  = new List <Role>();

                        foreach (var role in IFRSCoreModuleDefinition.GetRoles())
                        {
                            var localRole = existingRoles.Where(c => c.Name == role.Name).FirstOrDefault();

                            if (localRole == null)
                            {
                                localRole = new Role()
                                {
                                    Name = role.Name, Description = role.Description, SolutionId = solution.SolutionId, Type = RoleType.Application, Active = true, Deleted = false, CreatedBy = "Auto", CreatedOn = DateTime.Now, UpdatedBy = "Auto", UpdatedOn = DateTime.Now
                                };

                                localRole = roleRepository.Add(localRole);
                            }
                            else
                            {
                                localRole.Description = role.Description;
                                localRole.UpdatedOn   = DateTime.Now;
                                localRole             = roleRepository.Update(localRole);
                            }



                            updatedRoles.Add(localRole);
                        }

                        //Menus
                        var existingMenus = menuRepository.Get().Where(c => c.ModuleId == module.ModuleId).ToList();
                        var updatedMenus  = new List <Menu>();

                        var menuIndex = 0;

                        foreach (var menu in IFRSCoreModuleDefinition.GetMenus())
                        {
                            menuIndex += 1;

                            int?parentId = null;
                            if (!string.IsNullOrEmpty(menu.Parent))
                            {
                                var parentMenu = existingMenus.Where(c => c.Name == menu.Parent).FirstOrDefault();

                                if (parentMenu == null)
                                {
                                    parentMenu = menuRepository.Get().Where(c => c.ModuleId == module.ModuleId && c.Name == menu.Parent).FirstOrDefault();
                                }

                                if (parentMenu != null)
                                {
                                    parentId = parentMenu.MenuId;
                                }
                            }

                            var localMenu = existingMenus.Where(c => c.Name == menu.Name).FirstOrDefault();

                            if (localMenu == null)
                            {
                                localMenu = new Menu()
                                {
                                    Name = menu.Name, Alias = menu.Alias, Action = menu.Action, ActionUrl = menu.ActionUrl, ImageUrl = menu.ImageUrl, ModuleId = module.ModuleId, Position = menuIndex, ParentId = parentId, Active = true, Deleted = false, CreatedBy = "Auto", CreatedOn = DateTime.Now, UpdatedBy = "Auto", UpdatedOn = DateTime.Now
                                };

                                localMenu = menuRepository.Add(localMenu);
                            }
                            else
                            {
                                localMenu.Alias     = menu.Alias;
                                localMenu.Action    = menu.Action;
                                localMenu.ActionUrl = menu.ActionUrl;
                                localMenu.ImageUrl  = menu.ImageUrl;
                                localMenu.ModuleId  = module.ModuleId;
                                localMenu.Position  = menuIndex;
                                localMenu.ParentId  = parentId;
                                localMenu.UpdatedOn = DateTime.Now;

                                localMenu = menuRepository.Update(localMenu);
                            }

                            updatedMenus.Add(localMenu);
                        }

                        //MenuRoles
                        var menuIds           = updatedMenus.Select(c => c.MenuId).Distinct().ToArray();
                        var existingMenuRoles = menuRoleRepository.Get().Where(c => menuIds.Contains(c.MenuId)).ToList();

                        foreach (var menuRole in IFRSCoreModuleDefinition.GetMenuRoles())
                        {
                            var myMenu = updatedMenus.Where(c => c.Name == menuRole.MenuName).FirstOrDefault();
                            var myRole = updatedRoles.Where(c => c.Name == menuRole.RoleName).FirstOrDefault();

                            var localMenuRole = existingMenuRoles.Where(c => c.MenuId == myMenu.MenuId && c.RoleId == myRole.RoleId).FirstOrDefault();

                            if (localMenuRole == null)
                            {
                                localMenuRole = new MenuRole()
                                {
                                    MenuId = myMenu.MenuId, RoleId = myRole.RoleId, Active = true, Deleted = false, CreatedBy = "Auto", CreatedOn = DateTime.Now, UpdatedBy = "Auto", UpdatedOn = DateTime.Now
                                };

                                menuRoleRepository.Add(localMenuRole);
                            }
                            else
                            {
                                localMenuRole.MenuId    = myMenu.MenuId;
                                localMenuRole.RoleId    = myRole.RoleId;
                                localMenuRole.UpdatedOn = DateTime.Now;

                                menuRoleRepository.Update(localMenuRole);
                            }
                        }
                    }

                    ts.Complete();
                }
            });
        }
示例#30
0
        // ---------------------------------------------------------------------------------------------
        public ModuleDTO UpsertModule(ModuleDTO moduleReceived)
        {
            var                  id = moduleReceived.id;
            edumodule            module;
            List <test_question> oldQuestions = null;
            List <test_code>     oldCodes     = null;


            // MODUŁ
            // ...............................................................
            // utworzenie nowego modułu lub pobranie istniejącego
            if (id == 0)
            {
                module = new edumodule();
                ModuleMapper.CopyValues(moduleReceived, module);
                _moduleRepository.Add(module);
            }
            else
            {
                module = _moduleRepository.Get(id);
                _moduleRepository.SetNewValues(moduleReceived, module);
                oldQuestions = module.test_question.ToList();
                oldCodes     = module.test_code.ToList();
            }

            // PYTANIA
            // ...............................................................
            // usunięcie pytań, których nie ma w tablicy z nowymi pytaniami
            var newQuestions = moduleReceived.test_questions_DTO;

            foreach (var oldQ in oldQuestions)
            {
                if (newQuestions == null)
                {
                    _questionService.DeleteQuestion(oldQ.id);
                }
                else if (!newQuestions.Exists(newQ => newQ.id == oldQ.id))
                {
                    _questionService.DeleteQuestion(oldQ.id);
                }
            }

            // zapisanie nowych i odświeżenie starych pytań przypisanych do modułu
            if (moduleReceived.test_questions_DTO != null && moduleReceived.difficulty == "easy")
            {
                foreach (var new_question in moduleReceived.test_questions_DTO)
                {
                    _questionService.UpsertQuestion(new_question);
                }
            }


            // CODE TASKS
            // ...............................................................
            // usunięcie zadań z kodu, których nie ma w tablicy z nowymi zadaniami
            var newCodes = moduleReceived.test_codes_DTO;

            foreach (var oldC in oldCodes)
            {
                if (newCodes == null)
                {
                    _codeService.DeleteCode(oldC.id);
                }
                else if (!newCodes.Exists(newC => newC.id == oldC.id))
                {
                    _codeService.DeleteCode(oldC.id);
                }
            }

            // zapisanie nowych i odświeżenie starych pytań przypisanych do modułu
            if (moduleReceived.test_codes_DTO != null && moduleReceived.difficulty == "easy")
            {
                foreach (var new_code in moduleReceived.test_codes_DTO)
                {
                    _codeService.UpsertCode(new_code);
                }
            }



            // RETURN
            // ...............................................................
            return(GetDTOWithQuestions(module, -1));
        }