Beispiel #1
0
        public ActionResult Create([Bind(Include = "Name, Description, ImageMimeType, ImageData, UrlString")] Solution solution,
                                   HttpPostedFileBase image = null)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index", "SiteAdmin"));
            }

            if (image != null)
            {
                solution.ImageMimeType = image.ContentType;
                solution.ImageData     = new byte[image.ContentLength];
                image.InputStream.Read(solution.ImageData, 0, image.ContentLength);
            }

            try
            {
                _repository.Add(solution);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            return(RedirectToAction("Index", "SiteAdmin"));
        }
Beispiel #2
0
        public async Task AddSolution(Solution solution)
        {
            var entity = _mapper.Map <Data.Models.Solution>(solution);
            await _solutionRepository.Add(entity);

            foreach (var testResult in solution.TestResults)
            {
                testResult.SolutionId = entity.Id;
            }

            await _testResultService.AddTestResults(solution.TestResults);
        }
        public override void RegisterModule()
        {
            ExecuteFaultHandledOperation(() =>
            {
                ISolutionRepository solutionRepository            = _DataRepositoryFactory.GetDataRepository <ISolutionRepository>();
                systemCoreData.IModuleRepository moduleRepository = _DataRepositoryFactory.GetDataRepository <systemCoreData.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
                    systemCoreEntities.Module module = moduleRepository.Get().Where(c => c.Name == OpexModuleDefinition.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 == OpexModuleDefinition.SOLUTION_NAME).FirstOrDefault();
                        if (solution == null)
                        {
                            //register solution
                            solution = new Solution()
                            {
                                Name      = OpexModuleDefinition.SOLUTION_NAME,
                                Alias     = OpexModuleDefinition.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 systemCoreEntities.Module()
                            {
                                Name       = OpexModuleDefinition.MODULE_NAME,
                                Alias      = OpexModuleDefinition.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 OpexModuleDefinition.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 OpexModuleDefinition.GetMenus())
                        {
                            menuIndex      += 1;
                            Menu parentMenu = null;

                            int?parentId = null;
                            if (!string.IsNullOrEmpty(menu.Parent))
                            {
                                if (string.IsNullOrEmpty(menu.ParentModule))
                                {
                                    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();
                                    }
                                }
                                else
                                {
                                    var parentModule = moduleRepository.Get().Where(c => c.Name == menu.ParentModule).FirstOrDefault();

                                    if (parentModule != null)
                                    {
                                        parentMenu = menuRepository.Get().Where(c => c.ModuleId == parentModule.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 OpexModuleDefinition.GetMenuRoles())
                        {
                            var myMenu = updatedMenus.Where(c => c.Name == menuRole.MenuName).FirstOrDefault();
                            var myRole = existingRoles.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();
                }
            });
        }
 public void CreateSolution(Solution solution)
 {
     solutionsRepository.Add(solution);
 }