public async Task <IActionResult> Create([Bind("Id,Name,Description,StartDate,EndDate,CourseId")] Module @module)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@module);
                await _context.SaveChangesAsync();

                if (Request.IsAjax())
                {
                    var model = new ModulesViewModel
                    {
                        Id        = module.Id,
                        Name      = module.Name,
                        StartDate = module.StartDate,
                        EndDate   = module.EndDate
                    };

                    return(PartialView("ModulePartial", model));
                }


                return(RedirectToAction(nameof(Index)));
            }
            return(View(@module));
        }
Exemple #2
0
        private List <ModulesViewModel> BuildTree()
        {
            var vm = new List <ModulesViewModel>();

            using (var db = new MvcDemoContext())
            {
                var modulos = db.Modules.OrderBy(x => x.Order).ToList();
                var usuario = CarregarUsuario(db);
                var usuarioGrupoPermissao = db.UserGroupPermissions
                                            .FirstOrDefault(x => x.UserId == usuario.UserId);
                var permissaoFuncionalidade = db.FunctionalityPermissions.Where(x => x.PermissionGroupId == usuarioGrupoPermissao.PermissionGroupId && x.Read == true);
                var functionalities         = new List <Functionality>();
                foreach (var item in permissaoFuncionalidade)
                {
                    functionalities.Add(item.Functionality);
                }

                foreach (var modulo in modulos)
                {
                    var model = new ModulesViewModel
                    {
                        Nome            = modulo.Name,
                        ModuloId        = (int)modulo.ModuleId,
                        Icone           = modulo.Icon,
                        Ordem           = modulo.Order,
                        Functionalities = functionalities.Where(x => x.ModuleId == modulo.ModuleId).OrderBy(x => x.Order).ToList()
                    };
                    vm.Add(model);
                }
            }
            return(vm);
        }
        public ActionResult Edit(int id)
        {
            var modToEdit = ModRepository.GetModuleById(id,
                                                        m => m.Fields.Include <Field, FieldDataType>(f => f.FieldDataType),
                                                        m => m.Fields.Include <Field, FieldMetadata>(f => f.Metadata));

            if (modToEdit == null)
            {
                TempData["Message"] = "Módulo não encontrado.";
                return(RedirectToAction("Index", "Home"));
            }

            ModulesViewModel model = new ModulesViewModel()
            {
                Id           = modToEdit.Id,
                DisplayName  = modToEdit.DisplayName,
                DataTypeList = GetDataTypeList(),
                Type         = modToEdit.ModuleType
            };

            model.Fields.AddRange(
                modToEdit.Fields.ToList().Select(f => new ModuleField {
                ID               = f.ID,
                IsRequired       = f.IsRequired,
                IsReadOnly       = f.IsReadOnly,
                DataType         = f.FieldDataType.Name,
                FieldDisplayName = f.DisplayName,
                ShowInListMode   = f.ShowInListMode,
                Metadata         = f.Metadata.FirstOrDefault() != null ? f.Metadata.FirstOrDefault().Value : null                 // *1
            }));

            // *1 TODO: Despite the field-metadata relationship is 1-N, we're passing only the first entry to the view for now.
            // This will probably change in the future when we have multiple metadata entries for each field.
            return(View(model));
        }
Exemple #4
0
        //
        // GET: /Test/
        public ActionResult Index()
        {
            UATSytemDbEntities Db = new UATSytemDbEntities();

            //Module module = Db.Modules.SingleOrDefault (x=> x.Name=="FICO");

            List <Module> modulelist = Db.Modules.ToList();

            /*   //Code for updating
             *
             * var modulelist1 = Db.Modules.Where (x=> x.mId ==1 && x.Name=="FICO").ToList();
             * modulelist1.ForEach(m1 => m1.Name = "FI-CO");
             * Db.SaveChanges();
             */

            ModulesViewModel ModulesVM = new ModulesViewModel();

            List <ModulesViewModel> ModulesVMlist = modulelist.Select(x => new ModulesViewModel {
                mId = x.mId, Name = x.Name
            }).ToList();

            // ModulesVM.mId = module.mId;
            // ModulesVM.Name = module.Name;

            //ViewBag.NameList = list;

            return(View(ModulesVMlist));
        }
        public ActionResult Modules(string moduleName) //install a module
        {
            var success = false;

            CreateOrUpdateReport <Module> moduleInstallOrUpdateReport = null;

            try
            {
                moduleInstallOrUpdateReport = _reflectionContentManager.GetNewOrUpdatedModule(moduleName);
                _reflectionContentManager.Store(moduleInstallOrUpdateReport.Item);
                _reflectionContentManager.SaveChanges();
                success = true;
            }
            catch (Exception exception)
            {
                //TODO: Log
            }

            //TODO: Trouver une solution au UrlRewriting pour que les ActionLink et RedirectToAction etc fonctionne vers les url réécrites

            var viewModel = new ModulesViewModel
            {
                ModuleInfos = _reflectionContentManager.GetModuleInfos(),
                Message     = success
                                                  ? String.Format("Module {0} has been {1}.",
                                                                  moduleName,
                                                                  (moduleInstallOrUpdateReport.Action ==
                                                                   CreateOrUpdateActions.Updated
                                                                       ? "updated"
                                                                       : "installed"))
                                                  : "An error occured."
            };

            return(View(viewModel));
        }
        public ActionResult TeacherCourseActivitiesPartial(int id)
        {
            // Get the specifik module
            var module = context.Modules.FirstOrDefault(n => n.Id == id);

            module.Activities = module.Activities.OrderBy(n => n.StartDate).ToList();
            // List to store activities
            List <ActivityViewModel> newActivityList = new List <ActivityViewModel>();

            // Info about the module
            ModulesViewModel vm = new ModulesViewModel()
            {
                Id          = id,
                Name        = module.Name,
                Description = module.Description,
                StartDate   = module.StartDate,
                EndDate     = module.EndDate,
                Activities  = newActivityList
            };

            //Add viewmodels for every activity in a module
            foreach (var t in module.Activities)
            {
                newActivityList.Add(new ActivityViewModel
                {
                    Id          = t.Id,
                    Name        = t.Name,
                    Description = t.Description,
                    StartDate   = t.StartDate,
                    EndDate     = t.EndDate
                });
            }
            return(PartialView("TeacherCourseActivitiesPartial", vm));
        }
 public ModulesView(ModulesViewModel viewModel)
 {
     InitializeComponent();
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         DataContext = viewModel;
     }
 }
        public ActionResult Modules()
        {
            var viewModel = new ModulesViewModel
            {
                ModuleInfos = _reflectionContentManager.GetModuleInfos()
            };

            return(View(viewModel));
        }
        public ActionResult Create()
        {
            ModulesViewModel model = new ModulesViewModel()
            {
                DataTypeList = GetDataTypeList()
            };

            return(View(model));
        }
Exemple #10
0
        public IActionResult Index()
        {
            var viewModel = new ModulesViewModel();

            viewModel.Modules = client.Get();

            viewModel.Module = viewModel.Modules.FirstOrDefault();

            return(View(viewModel));
        }
Exemple #11
0
        public ActionResult Create(ModulesViewModel _model)
        {
            if (!ModelState.IsValid)
            {
                _model.DataTypeList = GetDataTypeList();
                return(View(_model));
            }

            if (_model.Fields.Count(f => f.ShowInListMode) == 0)
            {
                TempData["Message"] = "Pelo menos um dos campos deve ser visível na listagem.";
                _model.DataTypeList = GetDataTypeList();
                return(View(_model));
            }

            // retrieve the current account name and associate with the newly created module
            var acctName = RouteData.Values["account"] as string;

            if (String.IsNullOrWhiteSpace(acctName))
            {
                TempData["Message"] = "Conta não encontrada.";
                return(View(_model));
            }

            Module newModule = new Module()
            {
                DisplayName = _model.DisplayName,
                ModuleName  = _model.DisplayName.EscapeName(),
                User        = ModRepository.GetUserByName(Membership.GetUser().UserName), // associate the module with the current logged in user
                Account     = ModRepository.GetAccountByName(acctName),
                ModuleType  = _model.Type
            };

            _model.Fields.ToList().ForEach(f => {
                var newField = new Field {
                    DisplayName    = f.FieldDisplayName,
                    FieldName      = f.FieldDisplayName.EscapeName(),
                    FieldDataType  = ModRepository.GetDataTypeByName(f.DataType),
                    IsReadOnly     = f.IsReadOnly,
                    IsRequired     = f.IsRequired,
                    ShowInListMode = f.ShowInListMode
                };

                if (f.Metadata != null)
                {
                    newField.AddMetadata(f.Metadata);
                }
                newModule.Fields.Add(newField);
            });

            ModRepository.AddModule(newModule);

            TempData["Message"] = "Módulo salvo com sucesso.";
            return(RedirectToAction("Index", "Home"));
        }
Exemple #12
0
        public IActionResult Get(string id)
        {
            var viewModel = new ModulesViewModel();

            viewModel.Module = client.Get(id);

            // get all the modules for testing.
            // this is used to generate a list of modules
            viewModel.Modules = client.Get();

            return(View("Index", viewModel));
        }
Exemple #13
0
        /// <summary>
        /// Initialize an instance of the AppViewModel
        /// </summary>
        public AppViewModel()
        {
            AppSettings = new Settings();
            AppSettings.Load();

            ModuleVm  = new ModulesViewModel();
            HomeVm    = new HomeViewModel();
            SettingVm = new SettingsViewModel(AppSettings);
            ScriptsVm = new ScriptsViewModel();

            CurrentViewModel = HomeVm;

            SwitchViewCommand = new RelayCommand(ChangeView);
            InputTextCommand  = new RelayCommand(InputText);
        }
Exemple #14
0
        public void load_modules()
        {
            // Setup
            var viewModel    = new ModulesViewModel();
            var dependencies = new ModulesDependencies()
            {
                Services = new MockModulesServices()
            };

            viewModel.Initialize(dependencies);

            // Test
            var modules = viewModel.LoadModules();

            // Verify
            Assert.IsTrue(modules != null);
        }
Exemple #15
0
        public async Task <IActionResult> Show(string userGuid, int courseId)
        {
            var result = new ModulesViewModel();

            if (!string.IsNullOrWhiteSpace(userGuid) && courseId > 0)
            {
                result.UserGuid = userGuid;
                result.CourseId = courseId;

                result.Modules = await _dataRepository.GetAllModulesByUserGuidAndModuleIdAsync(userGuid, courseId);
            }
            else
            {
                result.Message = "Proszę o podanie identyfikatora użytkownika i kursu!";
            }

            return(View(result));
        }
Exemple #16
0
        private ModulesViewModel GetModules()
        {
            var path        = @"c:\temp\MEFModules";
            var conventions = new ConventionBuilder();

            conventions
            .ForTypesDerivedFrom <IModule>()
            .Export <IModule>()
            .Shared();

            var configuration = new ContainerConfiguration()
                                .WithAssembliesInPath(path, conventions);
            ModulesViewModel modules;

            using (var container = configuration.CreateContainer())
            {
                modules = new ModulesViewModel();
                container.SatisfyImports(modules);
            }
            return(modules);
        }
Exemple #17
0
        public ActionResult _ActivityListPartial(int id)
        {
            UserStore <Models.Identity.ApplicationUser>   userStore   = new UserStore <Models.Identity.ApplicationUser>(db);
            UserManager <Models.Identity.ApplicationUser> userManager = new UserManager <Models.Identity.ApplicationUser>(userStore);
            var courseID = userManager.FindByName(User.Identity.Name).CourseId.Id;
            ModulesViewModel activityList = new ModulesViewModel()
            {
                Activities = new List <ActivityViewModel>()
            };

            var act = db.Modules.FirstOrDefault(m => m.Id == id).Activities;

            foreach (var m in act)
            {
                activityList.Activities.Add(new ActivityViewModel
                {
                    Name        = m.Name,
                    StartDate   = m.StartDate,
                    Description = m.Description,
                    EndDate     = m.EndDate
                });
            }
            return(PartialView(activityList));
        }
 public ModulesView()
 {
     InitializeComponent();
     DataContext = new ModulesViewModel();
 }
Exemple #19
0
 public ModulesView(MainViewModel mainViewModel, PS3API ps3)
 {
     ViewModel = new ModulesViewModel(DialogCoordinator.Instance, mainViewModel, ps3);
     InitializeComponent();
 }
        public ModulesWindow(MyProcess myProcess)
        {
            InitializeComponent();

            DataContext = new ModulesViewModel(myProcess);
        }
Exemple #21
0
        public ActionResult Edit(ModulesViewModel _model)
        {
            if (!ModelState.IsValid)
            {
                _model.DataTypeList = GetDataTypeList();
                return(View(_model));
            }

            var modToEdit = ModRepository.GetModuleById(_model.Id,
                                                        m => m.Fields.Include <Field, FieldDataType>(f => f.FieldDataType),
                                                        m => m.Fields.Include <Field, FieldMetadata>(f => f.Metadata),
                                                        m => m.Rows.Include <Row, Cell>(r => r.Cells));

            if (modToEdit == null)
            {
                TempData["Message"] = "Módulo não encontrado.";
                _model.DataTypeList = GetDataTypeList();
                return(View(_model));
            }

            modToEdit.DisplayName = _model.DisplayName;

            if (_model.Fields.Count(f => f.ShowInListMode) == 0)
            {
                TempData["Message"] = "Pelo menos um dos campos deve ser visível na listagem.";
                _model.DataTypeList = GetDataTypeList();
                return(View(_model));
            }

            // handle modified and added fields
            foreach (ModuleField f in _model.Fields)
            {
                Field dbField = modToEdit.Fields.FirstOrDefault(fld => fld.ID == f.ID);

                bool bNeedToAdd = (dbField == null);

                if (dbField == null)
                {
                    dbField = new Field();
                }

                if (!bNeedToAdd)
                {
                    dbField.FieldDataTypeReference.Load();
                    dbField.Metadata.Load();

                    if (dbField.FieldDataType.Name != f.DataType)
                    {
                        // field type changed. set it to null on all matching rows
                        modToEdit.Rows.ToList().ForEach(r => {
                            r.Cells.Load();

                            r.Cells
                            .ToList()
                            .ForEach(rf => {
                                rf.FieldReference.Load();

                                if (rf.Field.FieldName == dbField.FieldName)
                                {
                                    rf.Data = null;
                                }
                            });
                        });
                    }
                }

                dbField.DisplayName    = f.FieldDisplayName;
                dbField.FieldName      = f.FieldDisplayName.EscapeName();
                dbField.FieldDataType  = ModRepository.GetDataTypeByName(f.DataType);
                dbField.IsReadOnly     = f.IsReadOnly;
                dbField.IsRequired     = f.IsRequired;
                dbField.ShowInListMode = f.ShowInListMode;
                dbField.Module         = modToEdit as Module;

                if (f.Metadata != null)
                {
                    dbField.AddMetadata(f.Metadata);
                }

                if (bNeedToAdd)
                {
                    ModRepository.AddField(dbField);

                    modToEdit.Rows.ToList()
                    .ForEach(row => {
                        Cell rf = new Cell()
                        {
                            Field = dbField, Row = row
                        };
                        ModRepository.AddCell(rf);
                    });
                }
            }

            ModRepository.Save();

            TempData["Message"] = "Módulo salvo com sucesso.";
            return(RedirectToAction("List", "DynamicModule", new { moduleid = _model.Id, modulename = modToEdit.ModuleName }));
        }