public IActionResult Post([FromBody] TopologiaViewModel model, int idProjeto) { try { model.ProjetoId = idProjeto; if (_unitOfw.ProjetoRepository.Count(y => y.Id == idProjeto) == 0) { BaseViewModel <string> notFound = new BaseViewModel <string>("Projeto Not Found!"); return(Ok(notFound)); } if (_unitOfw.TopologiaRepository.Count(y => y.Nome == model.Nome && y.Id != model.Id) > 0) { BaseViewModel <string> already = new BaseViewModel <string>("Nome ja existe!"); return(Ok(already)); } if (model.Id > 0) { _topologiaAppService.Update(model); } else { _topologiaAppService.Save(model); } BaseViewModel <TopologiaViewModel> baseObj = new BaseViewModel <TopologiaViewModel>(model, "Topologia Saved Successfully!", ""); return(Ok(baseObj)); } catch (Exception ex) { throw; } }
public void Save(TopologiaViewModel model) { using (var context = new VCMContext()) { using (var transaction = context.Database.BeginTransaction()) { try { Topologia topologia = _mapper.Map <Topologia>(model); context.Topologia.Add(topologia); //pr_VCM_TopologiaInsert //TODO: esta fixo na function o "Sistema" ([fn_find_TipoPropriedadeByNome]) int tipoPropriedadeId = _unitOfw.TipoPropriedadeRepository.Get(y => y.Nome == "Padrao").Select(y => y.Id).FirstOrDefault(); int tipoValorId = _unitOfw.TipoValorRepository.Get(y => y.Nome == "Sistema").Select(y => y.Id).FirstOrDefault(); //cadeiaId = _unitOfw.ProjetoRepository.Get(y => y.Topologia.Any(t => t.Id == tobeSave.Id)).Select(c => c.Cadeia.Id).FirstOrDefault(); //TODO: CENARIO1 Fixo na Procedure [pr_VCM_CenarioInsert] Cenario cenario = new Cenario { Nome = "CENARIO1", TopologiaId = topologia.Id }; context.Cenario.Add(cenario); FluxogramaDrawing fluxogramaDrawing = new FluxogramaDrawing(topologia.Id, 0, 0, 1); context.FluxogramaDrawing.Add(fluxogramaDrawing); PropriedadeTopologiaCreate(tipoPropriedadeId, topologia.Id, context); context.SaveChanges(); transaction.Commit(); model.Id = topologia.Id; model.CenarioId = cenario.Id; model.Id = topologia.Id; model.FluxogramaId = fluxogramaDrawing.Id; } catch (Exception ex) { transaction.Rollback(); } } } }
public void Update(TopologiaViewModel model) { _unitOfw.TopologiaRepository.AddOrUpdate(_mapper.Map <Topologia>(model)); }