Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public ActionResult Query(int moduleid, string modulename, int?id)
        {
            var doverApi = new ModuleApi(ModRepository);

            var module = ModRepository.GetModuleById(moduleid,
                                                     m => m.Fields.Include <Field, FieldDataType>(f => f.FieldDataType),
                                                     m => m.Rows.Include <Row, Cell>(r => r.Cells));

            var data = doverApi.GetModuleData(module, id, Request.QueryString);

            ModRepository.IncrementModuleRequestCount(module.Id);

            return(View(data));
        }
Esempio n. 3
0
        public ActionResult Delete(int id)
        {
            var modToDelete = ModRepository.GetModuleById(id);

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

            ModRepository.DeleteObject(modToDelete);
            ModRepository.Save();

            TempData["Message"] = "Módulo removido com sucesso.";
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 4
0
        public ActionResult module(int moduleid, DynamicModuleViewModel _entryToCreate)
        {
            var doverApi     = new ModuleApi(ModRepository);
            var module       = ModRepository.GetModuleById(moduleid, m => m.Fields);
            var result       = String.Empty;
            var filteredList = new DynamicModuleFieldList();

            filteredList.AddRange(_entryToCreate.Fields.Where(f => CheckFieldExistency(f)));
            _entryToCreate.Fields = filteredList;

            try {
                doverApi.CreateModule(module, _entryToCreate);
                result = "<result>Success</result>";
            }
            catch (CreateModuleFailedException) {
                result = "<result>Failure</result>";
            }

            return(Content(result, "text/xml", Encoding.UTF8));
        }
Esempio n. 5
0
        public ActionResult module(int moduleid, int?id, DynamicModuleViewModel _entryToEdit)
        {
            var result = String.Empty;

            try {
                var doverApi     = new ModuleApi(ModRepository);
                var module       = ModRepository.GetModuleById(moduleid, m => m.Rows.Include <Row, Cell>(r => r.Cells), m => m.Fields);
                var filteredList = new DynamicModuleFieldList();

                filteredList.AddRange(_entryToEdit.Fields.Where(f => CheckFieldExistency(f)));
                _entryToEdit.Fields = filteredList;

                doverApi.SetModuleData(module, id, _entryToEdit, true);
                result = "<result>Success</result>";
            }
            catch (Exception e) {
                result = "<result>Failure</result>";
            }

            return(Content(result, "text/xml", Encoding.UTF8));
        }
Esempio n. 6
0
        public ActionResult modules(string moduleid)
        {
            var dataList = new DynamicModuleApiResultList();

            if (!String.IsNullOrWhiteSpace(moduleid) &&
                Request.QueryString.Count == 0)
            {
                var doverApi = new ModuleApi(ModRepository);

                string[] ids = moduleid.Split(",".ToCharArray());

                foreach (var id in ids)
                {
                    int nid;
                    if (!Int32.TryParse(id.Trim(), out nid))
                    {
                        continue;
                    }

                    var module = ModRepository.GetModuleById(nid,
                                                             m => m.Fields.Include <Field, FieldDataType>(f => f.FieldDataType),
                                                             m => m.Rows.Include <Row, Cell>(r => r.Cells));

                    if (module == null)
                    {
                        continue;
                    }

                    dataList.Add(doverApi.GetModuleData(module, null, Request.QueryString));

                    ModRepository.IncrementModuleRequestCount(module.Id);
                }
            }

            return(View(dataList));
        }
Esempio n. 7
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 }));
        }