/// <summary> /// Creates the provided module. /// </summary> /// <param name="_module">The module to be created</param> public void AddModule(Module _module) { if (_module == null) { throw new ArgumentNullException("_module"); } db.AddToModule(_module); db.SaveChanges(); }
public FakeModuleRepository() { AllModules = new List<IModule>(); AllRows = new List<Row>(); var converter = FieldValueConversion.GetConverter(Type.GetType("System.String")); int j = 100; int k = 200; int l = 300; int m = 400; for(int i = 0; i < 101; i++) { var module = new Module() { DisplayName = "Test Module " + i, ModuleName = "The-test-module-" + i, Id = i, ModuleType = i % 3, User = new User() { UserId = FakeModuleMembership.FakeUserId } }; var field = new Field() { DisplayName = "Test field " + i, FieldName = "TestField" + i, ID = k--, ShowInListMode = true, IsRequired = true, FieldDataType = new FieldDataType() { Name = "System.String", ID = l--, FriendlyName = "Test data type " + i } }; module.Fields.Add(field); for (int z = 0; z < 20; z++) { module.Rows.Add(new Row() { ID = m--, Cells = new EntityCollection<Cell>() { new Cell() { Data = converter.Serialize(new DynamicModuleField { Data = "Some data " + z }), ID = j--, Field = field }} }); } AllModules.Add(module); AllRows.AddRange(AllModules.FirstOrDefault().Rows); } }
/// <summary> /// Deprecated Method for adding a new object to the Module EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToModule(Module module) { base.AddObject("Module", module); }
/// <summary> /// Create a new Module object. /// </summary> /// <param name="displayName">Initial value of the DisplayName property.</param> /// <param name="moduleName">Initial value of the ModuleName property.</param> /// <param name="moduleType">Initial value of the ModuleType property.</param> /// <param name="id">Initial value of the Id property.</param> public static Module CreateModule(global::System.String displayName, global::System.String moduleName, global::System.Int32 moduleType, global::System.Int32 id) { Module module = new Module(); module.DisplayName = displayName; module.ModuleName = moduleName; module.ModuleType = moduleType; module.Id = id; return module; }
public void AddModule(Module _module) { throw new NotImplementedException(); }
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"); }
private ActionResult ViewModule(Module _module, int? id, bool creating = false) { if (id != null && _module.Rows.FirstOrDefault(row => row.ID == id) == null) { TempData["Message"] = "Registro não encontrado."; return this.RedirectToAction("List"); } DynamicModuleViewModel modelRow = new DynamicModuleViewModel() { ID = id ?? -1, ModuleName = _module.ModuleName, DisplayName = _module.DisplayName }; foreach (Field field in _module.Fields) { Cell rowField = null; if (!creating) { rowField = (id != null) ? field.Cells.FirstOrDefault(rf => rf.Row.ID == id) : field.Cells.FirstOrDefault(); } var fieldDataTpe = Type.GetType(field.FieldDataType.Name); var converter = FieldValueConversion.GetConverter(fieldDataTpe); var modelField = new DynamicModuleField() { DisplayName = field.DisplayName, PropertyName = field.FieldName, IsReadOnly = field.IsReadOnly, IsRequired = field.IsRequired, DataType = fieldDataTpe }; modelField.Data = converter.Deserialize( rowField, new ConversionContext { Field = field, Module = _module, Repository = ModRepository }); modelRow.Fields.Add(modelField); } return View(modelRow); }