public async System.Threading.Tasks.Task Save() { RequestTopologiaSave topologiaToBeSave = new RequestTopologiaSave { Nome = "Insert" + DateTime.Now, ProjetoId = 1, Id = 0 }; HttpResponseMessage response = await _clientCall.Save(_baseController + "Save/", JsonConvert.SerializeObject(topologiaToBeSave)); Assert.IsTrue(response.IsSuccessStatusCode); if (response.IsSuccessStatusCode) { var retorno = await response.Content.ReadAsStringAsync(); RequestTopologiaSave topologiaRetorno = JsonConvert.DeserializeObject <RequestTopologiaSave>(JObject.Parse(retorno)["data"].ToString()); Topologia topologiaAfterSave = _unitOfw.TopologiaRepository.Get(y => y.Id == topologiaRetorno.Id).FirstOrDefault(); Assert.AreEqual(topologiaToBeSave.Nome, topologiaAfterSave.Nome); Assert.AreEqual(topologiaToBeSave.ProjetoId, topologiaAfterSave.ProjetoId); } }
public async System.Threading.Tasks.Task Delete() { try { int idTopologia = 6118; RequestTopologiaSave topologia = new RequestTopologiaSave(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(_baseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.DeleteAsync(_baseController + "Delete/" + idTopologia); Assert.IsTrue(response.IsSuccessStatusCode); if (response.IsSuccessStatusCode) { var retorno = await response.Content.ReadAsStringAsync(); Topologia topologiaGet = _unitOfw.TopologiaRepository.Get(y => y.Id == idTopologia).FirstOrDefault(); Assert.IsNull(topologiaGet); } } } 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 async System.Threading.Tasks.Task Get() { int idTopologia = _unitOfw.TopologiaRepository.Get().ToList().FirstOrDefault().Id; HttpResponseMessage response = await _clientCall.Detail(_baseController + "Detail/" + idTopologia); Assert.IsTrue(response.IsSuccessStatusCode); if (response.IsSuccessStatusCode) { var retorno = await response.Content.ReadAsStringAsync(); Topologia topologia = JsonConvert.DeserializeObject <Topologia>(JObject.Parse(retorno)["data"].ToString()); Assert.IsNotNull(topologia); Assert.AreEqual(idTopologia, topologia.Id); } }
public IActionResult Delete(int id) { try { Topologia model = _unitOfw.TopologiaRepository.GetWithIncludeAll(y => y.Id == id); if (model == null) { BaseViewModel <string> notFound = new BaseViewModel <string>("Topologia Not Found!"); return(Ok(notFound)); } _unitOfw.TopologiaRepository.Delete(model); BaseViewModel <string> baseObj = new BaseViewModel <string>("Topologia Deleted Successfully!"); return(Ok(baseObj)); } catch (Exception ex) { return(BadRequest(ex)); } }