private static ApplicationDbContext GetContextWithoutData() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; context = new ApplicationDbContext(options); var novoCasal = new Casal { CasalID = 1, IdadeHomem = 45, RacaHomem = EtniaEnum.Caucasiano, AlturaHomem = 177, CorCabeloHomem = CorCabeloEnum.Castanho, GrupoSanguineoHomem = GrupoSanguineoEnum.ANeg, TexturaCabeloHomem = TexturaCabeloEnum.Grisalho, CorOlhosHomem = CorOlhosEnum.Castanho, CorPeleHomem = CorPeleEnum.Clara, IdadeMulher = 38, RacaMulher = EtniaEnum.Negro, AlturaMulher = 155, CorCabeloMulher = CorCabeloEnum.Cinzento, GrupoSanguineoMulher = GrupoSanguineoEnum.ABNeg, TexturaCabeloMulher = TexturaCabeloEnum.Ondulado, CorOlhosMulher = CorOlhosEnum.Outro, CorPeleMulher = CorPeleEnum.MuitoClara }; context.Add(novoCasal); context.SaveChanges(); var novoPedidoGametas = new PedidoGametas { PedidoGametasId = 1, CasalId = 1, Data = DateTime.UtcNow, Centro = "Centro PMA Leiria", RefExterna = "PMLEI2002", EstadoProcessoPedido = EstadoProcesso.EmAnalise }; context.Add(novoPedidoGametas); context.SaveChanges(); return(context); }
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)); }