public IActionResult Edit(string objectName, Guid id, IFormCollection form) { ModelState.Clear(); var domainType = Typer.GetTyper(objectName); var vmType = Typer.GetRefTyper("ViewModel", domainType, TyperAction.Update); if (vmType == null) { return(NotFound()); } var model = BindModel(form, vmType); if (!TryValidateModel(model)) { var viewName = $"{objectName}/Edit"; return(View(viewName, model)); } var entity = repositoryRead.GetSingle(objectName, id) as IDefaultEntity; Mapper.Map(model, entity, vmType, domainType); service.Update(entity); uoW.SaveChanges(); return(RedirectToAction("List", new { objectName })); }
public IActionResult New(string objectName, IFormCollection form) { ModelState.Clear(); var domainType = Typer.GetTyper(objectName); var vmType = Typer.GetRefTyper("ViewModel", domainType, TyperAction.Insert); if (vmType == null) { return(NotFound()); } var model = BindModel(form, vmType); var viewName = $"{objectName}New"; if (!TryValidateModel(model)) { return(View(viewName, model)); } var entity = Mapper.Map(model, model.GetType(), domainType) as IDefaultEntity; service.Add(entity); uoW.SaveChanges(); return(RedirectToAction("List", new { objectName })); }
public IActionResult Get(string id) { _typer.SetCurrentTyper(typeof(Turma)); var turma = repositoryRead.GetSingle(id) as Turma; if (turma == null) { return(NotFound(id)); } _typer.SetCurrentTyper(typeof(Aluno)); var alunos = repositoryRead.Search <Aluno>(x => x.TurmaId == id); turma.SetAlunos(alunos); _typer.SetCurrentTyper(typer: typeof(Domain.Entities.Chamada)); var chamadas = repositoryRead.Search <Domain.Entities.Chamada>(x => x.TurmaId == id); turma.SetChamadas(chamadas); _typer.SetCurrentTyper(typeof(Turma)); var tipoModelTurma = _typer.GetRefTyper("ViewModel", TyperAction.GetSingle); var model = mapper.Map(turma, typeof(Turma), tipoModelTurma); return(ResponseApi(model)); }
public IActionResult New(string objectName) { var tipoModel = Typer.GetRefTyper("ViewModel", objectName, TyperAction.GetSingle); var model = tipoModel.CreateInstance(); var viewName = $"{objectName}/New"; return(View(viewName, model)); }
public IActionResult Get(string objectName) { ModelState.Clear(); if (!_typer.TrySetCurrentTyper(objectName)) { return(BadRequest()); } var entidades = repositoryRead.GetAll(); if (entidades == null) { return(ResponseApi(null)); } var tipoModel = _typer.GetRefTyper("ViewModel", TyperAction.GetAll); if (tipoModel == null) { return(ResponseApi(entidades)); } var models = mapper.Map(entidades, entidades.GetType(), typeof(IEnumerable <>).MakeGenericType(tipoModel)); return(ResponseApi(models)); }
public IActionResult List(string objectName) { ModelState.Clear(); var entidades = repositoryRead.GetAll(objectName); var tipoModel = Typer.GetRefTyper("ViewModel", objectName, TyperAction.GetAll); var models = Mapper.Map(entidades, entidades.GetType(), typeof(IEnumerable <>).MakeGenericType(tipoModel)); var viewName = $"{objectName}/List"; return(View(viewName, models)); }
public void Add(IDefaultModel entity) { var valid = true; if (_repository.GetSingle(entity.Id) != null) { return; } var validatorTyper = _typer.GetRefTyper("Validator", TyperAction.Insert); if (validatorTyper != null) { var validator = _serviceBuilder.GetService(validatorTyper); valid = (validator as IValidator).Run(entity); } if (valid) { _repository.Add(entity); } return; }