public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var pedidoGam = await _context.PedidoGametas.SingleOrDefaultAsync(p => p.PedidoGametasId == id); var casalPedido = await _context.Casal.SingleOrDefaultAsync(c => c.CasalID == pedidoGam.CasalId); if (pedidoGam == null || casalPedido == null) { return(NotFound()); } var pedidoGamViewModel = new PedidoGametasViewModel { Id = pedidoGam.PedidoGametasId, Data = pedidoGam.Data, Centro = pedidoGam.Centro, RefExterna = pedidoGam.RefExterna, EstadoProcessoPedido = pedidoGam.EstadoProcessoPedido, OriginouGravidez = casalPedido.OriginouGravidez, NrFilhos = casalPedido.NrFilhos, IdadeHomem = casalPedido.IdadeHomem, RacaHomem = casalPedido.RacaHomem, AlturaHomem = casalPedido.AlturaHomem, CorCabeloHomem = casalPedido.CorCabeloHomem, GrupoSanguineoHomem = casalPedido.GrupoSanguineoHomem, TexturaCabeloHomem = casalPedido.TexturaCabeloHomem, CorOlhosHomem = casalPedido.CorOlhosHomem, CorPeleHomem = casalPedido.CorPeleHomem, IdadeMulher = casalPedido.IdadeMulher, RacaMulher = casalPedido.RacaMulher, AlturaMulher = casalPedido.AlturaMulher, CorCabeloMulher = casalPedido.CorCabeloMulher, GrupoSanguineoMulher = casalPedido.GrupoSanguineoMulher, TexturaCabeloMulher = casalPedido.TexturaCabeloMulher, CorOlhosMulher = casalPedido.CorOlhosMulher, CorPeleMulher = casalPedido.CorPeleMulher }; return(View(pedidoGamViewModel)); //if (id == null) //{ // return NotFound(); //} //var pedidoGametasViewModel = await _context.PedidoGametasViewModel // .SingleOrDefaultAsync(m => m.Id == id); //if (pedidoGametasViewModel == null) //{ // return NotFound(); //} //return View(pedidoGametasViewModel); }
public async Task <IActionResult> Edit(int id, [Bind("Id,IdadeHomem,RacaHomem,AlturaHomem,CorCabeloHomem,GrupoSanguineoHomem,TexturaCabeloHomem,CorOlhosHomem,CorPeleHomem,IdadeMulher,RacaMulher,AlturaMulher,CorCabeloMulher,GrupoSanguineoMulher,TexturaCabeloMulher,CorOlhosMulher,CorPeleMulher,OriginouGravidez,NrFilhos")] PedidoGametasViewModel pedidoGametasViewModel) { var pedidoGam = await _context.PedidoGametas.AsNoTracking().SingleOrDefaultAsync(p => p.PedidoGametasId == pedidoGametasViewModel.Id); var casalPedido = await _context.Casal.AsNoTracking().SingleOrDefaultAsync(c => c.CasalID == pedidoGam.CasalId); if (pedidoGam == null || casalPedido == null) { return(NotFound()); } if (id != pedidoGam.PedidoGametasId) { return(NotFound()); } if (ModelState.IsValid) { try { var casalToUpdate = new Casal { CasalID = casalPedido.CasalID, OriginouGravidez = pedidoGametasViewModel.OriginouGravidez, NrFilhos = pedidoGametasViewModel.NrFilhos, IdadeHomem = pedidoGametasViewModel.IdadeHomem, RacaHomem = pedidoGametasViewModel.RacaHomem, AlturaHomem = pedidoGametasViewModel.AlturaHomem, CorCabeloHomem = pedidoGametasViewModel.CorCabeloHomem, GrupoSanguineoHomem = pedidoGametasViewModel.GrupoSanguineoHomem, TexturaCabeloHomem = pedidoGametasViewModel.TexturaCabeloHomem, CorOlhosHomem = pedidoGametasViewModel.CorOlhosHomem, CorPeleHomem = pedidoGametasViewModel.CorPeleHomem, IdadeMulher = pedidoGametasViewModel.IdadeMulher, RacaMulher = pedidoGametasViewModel.RacaMulher, AlturaMulher = pedidoGametasViewModel.AlturaMulher, CorCabeloMulher = pedidoGametasViewModel.CorCabeloMulher, GrupoSanguineoMulher = pedidoGametasViewModel.GrupoSanguineoMulher, TexturaCabeloMulher = pedidoGametasViewModel.TexturaCabeloMulher, CorOlhosMulher = pedidoGametasViewModel.CorOlhosMulher, CorPeleMulher = pedidoGametasViewModel.CorPeleMulher }; if (casalToUpdate.OriginouGravidez != SimNaoEnum.Indefinido) { var pedidoGamToUpdate = new PedidoGametas { PedidoGametasId = pedidoGam.PedidoGametasId, CasalId = casalToUpdate.CasalID, Data = pedidoGam.Data, Centro = pedidoGam.Centro, RefExterna = pedidoGam.RefExterna, EstadoProcessoPedido = EstadoProcesso.RegisteiResultadosCasal }; _context.Update(pedidoGamToUpdate); await _context.SaveChangesAsync(); } _context.Update(casalToUpdate); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(RedirectToAction(nameof(Index))); } return(View(pedidoGametasViewModel)); }
public async Task <IActionResult> Create([Bind("Id,Data,Centro,RefExterna,IdadeHomem,RacaHomem,AlturaHomem,CorCabeloHomem,GrupoSanguineoHomem,TexturaCabeloHomem,CorOlhosHomem,CorPeleHomem,IdadeMulher,RacaMulher,AlturaMulher,CorCabeloMulher,GrupoSanguineoMulher,TexturaCabeloMulher,CorOlhosMulher,CorPeleMulher")] PedidoGametasViewModel pedidoGametasViewModel, Microsoft.AspNetCore.Http.IFormFile fileHomem, Microsoft.AspNetCore.Http.IFormFile fileMulher) { if (ModelState.IsValid) { var novoCasal = new Models.Casal { OriginouGravidez = SimNaoEnum.Indefinido, NrFilhos = 0, IdadeHomem = pedidoGametasViewModel.IdadeHomem, RacaHomem = pedidoGametasViewModel.RacaHomem, AlturaHomem = pedidoGametasViewModel.AlturaHomem, CorCabeloHomem = pedidoGametasViewModel.CorCabeloHomem, GrupoSanguineoHomem = pedidoGametasViewModel.GrupoSanguineoHomem, TexturaCabeloHomem = pedidoGametasViewModel.TexturaCabeloHomem, CorOlhosHomem = pedidoGametasViewModel.CorOlhosHomem, CorPeleHomem = pedidoGametasViewModel.CorPeleHomem, IdadeMulher = pedidoGametasViewModel.IdadeMulher, RacaMulher = pedidoGametasViewModel.RacaMulher, AlturaMulher = pedidoGametasViewModel.AlturaMulher, CorCabeloMulher = pedidoGametasViewModel.CorCabeloMulher, GrupoSanguineoMulher = pedidoGametasViewModel.GrupoSanguineoMulher, TexturaCabeloMulher = pedidoGametasViewModel.TexturaCabeloMulher, CorOlhosMulher = pedidoGametasViewModel.CorOlhosMulher, CorPeleMulher = pedidoGametasViewModel.CorPeleMulher }; var pathUpload = Path.Combine(_hostingEnvironment.WebRootPath, "uploads", "casais"); var fileUpload = ""; //save image if (fileHomem.Length > 0) { fileUpload = await fileHomem.SaveFileDefault(_hostingEnvironment, pathUpload); if (fileUpload != "") { var fotoCasal = MatchHelper.MicrosoftCognitiveServices.Faces.AddFaceToFaceList( Path.Combine(pathUpload, fileUpload), fileUpload); novoCasal.FotoHomemId = fotoCasal.ToString(); } } if (fileMulher.Length > 0) { fileUpload = await fileMulher.SaveFileDefault(_hostingEnvironment, Path.Combine(_hostingEnvironment.WebRootPath, "uploads", "casais")); if (fileUpload != "") { var fotoCasal = MatchHelper.MicrosoftCognitiveServices.Faces.AddFaceToFaceList( Path.Combine(pathUpload, fileUpload), fileUpload); novoCasal.FotoHomemId = fotoCasal.ToString(); } } await _context.Casal.AddAsync(novoCasal); await _context.SaveChangesAsync(); var objNovoCasal = await _context.Casal.LastOrDefaultAsync(); var novoPedidoGametas = new PedidoGametas { CasalId = objNovoCasal.CasalID, Data = pedidoGametasViewModel.Data, Centro = pedidoGametasViewModel.Centro, RefExterna = pedidoGametasViewModel.RefExterna, EstadoProcessoPedido = EstadoProcesso.EmAnalise }; await _context.PedidoGametas.AddAsync(novoPedidoGametas); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pedidoGametasViewModel)); }