public bool AGREGAR(Fotos entidad) { return(repositorio.Create(entidad)); }
public bool Modificar(Fotos entidad) { return(repositorio.Update(entidad)); }
private void Apply(FotoRemovidaAnuncioEvent @event) { Fotos = Fotos.Remover(@event.Foto); }
private void Apply(TodasFotosRemovidasAnuncioEvent @event) { Fotos = Fotos.Limpar(); }
private void Apply(FotoAdicionadaAnuncioEvent @event) { Fotos = Fotos.Adicionar(@event.Foto); }
private void gerarRel(int tipo) { StreamWriter wr; switch (tipo) { case 1: #region Gerar relatório da última última foto cadastrada para as obras wr = new StreamWriter(path + "relFotos.html"); wr.WriteLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/>"); wr.WriteLine("<html>"); wr.WriteLine("<head>"); wr.WriteLine("<meta name='viewport' content='width=device-width, initial-scale=1'>"); wr.WriteLine("<meta charset='utf-8'>"); wr.WriteLine("<link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>"); wr.WriteLine("<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js'></script>"); wr.WriteLine("<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script>"); wr.WriteLine("<div class='container'>"); wr.WriteLine("<h2>Relatório da Última Foto Cadastrada para as Obras</h2>"); wr.WriteLine("<div class='table-responsive'>"); wr.WriteLine("<table class='table table-hover'>"); wr.WriteLine("<thead>"); wr.WriteLine("<tr>"); wr.WriteLine("<th>Código Obra</th>"); wr.WriteLine("<th>Cliente</th>"); wr.WriteLine("<th>Endereço</th>"); wr.WriteLine("<th>Data Última Foto</th>"); wr.WriteLine("<th>Foto</th>"); wr.WriteLine("</tr>"); wr.WriteLine("</thead>"); wr.WriteLine("</tbody>"); try { foreach (Obras obra in obrasDAO.select()) { wr.WriteLine("<tr><td>" + obra.Id + "</td>"); wr.WriteLine("<td>" + obra.Cliente.Nome + "</td>"); wr.WriteLine("<td>" + obra.Endereco + "</td>"); try { Fotos foto = fotosDAO.select().Where(x => x.Obra.Id == obra.Id).Last(); wr.WriteLine("<td>" + foto.Data.ToString("dd/MM/yyyy") + "</td>"); wr.WriteLine("<td><img src='" + @"C:\xampp\htdocs\fotos\" + foto.Id + "." + foto.Tipo + "' width=100 height=80></td></tr>"); } catch { wr.WriteLine("<td>" + "-" + "</td>"); wr.WriteLine("<td>" + "Não possui foto cadastrada" + "</td></tr>"); } } } catch { } wr.WriteLine("</tbody>"); wr.WriteLine("</table>"); wr.WriteLine("</div>"); wr.WriteLine("</div>"); wr.WriteLine("</body>"); wr.WriteLine("</html>"); wr.Close(); #endregion break; case 2: #region Gerar relatório dos agendamentos das obras que estão por vir wr = new StreamWriter(path + "relAgendObras.html"); wr.WriteLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/>"); wr.WriteLine("<html>"); wr.WriteLine("<head>"); wr.WriteLine("<meta name='viewport' content='width=device-width, initial-scale=1'>"); wr.WriteLine("<meta charset='utf-8'>"); wr.WriteLine("<link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>"); wr.WriteLine("<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js'></script>"); wr.WriteLine("<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script>"); wr.WriteLine("<div class='container'>"); wr.WriteLine("<h2>Relatório dos Agendamentos Futuros das Obras</h2>"); wr.WriteLine("<div class='table-responsive'>"); wr.WriteLine("<table class='table table-hover'>"); wr.WriteLine("<thead>"); wr.WriteLine("<tr>"); wr.WriteLine("<th>Código Obra</th>"); wr.WriteLine("<th>Cliente</th>"); wr.WriteLine("<th>Endereço</th>"); wr.WriteLine("<th>Data Agendamento</th>"); wr.WriteLine("<th>Assunto Agendamento</th>"); wr.WriteLine("<th>Observação Agendamento</th>"); wr.WriteLine("</tr>"); wr.WriteLine("</thead>"); wr.WriteLine("</tbody>"); try { foreach (Agendamentos agend in agendDAO.select().Where(x => x.Data >= DateTime.Today && x.Obra != null)) { wr.WriteLine("<tr><td>" + agend.Obra.Id + "</td>"); try { Obras obras = obrasDAO.select().Where(x => x.Id == agend.Obra.Id).First(); wr.WriteLine("<td>" + obras.Cliente.Nome + "</td>"); } catch { } wr.WriteLine("<td>" + agend.Obra.Endereco + "</td>"); wr.WriteLine("<td>" + agend.Data.ToString("dd/MM/yyyy") + "</td>"); wr.WriteLine("<td>" + agend.Assunto + "</td>"); wr.WriteLine("<td>" + agend.Observacao + "</td>"); } } catch { } wr.WriteLine("</tbody>"); wr.WriteLine("</table>"); wr.WriteLine("</div>"); wr.WriteLine("</div>"); wr.WriteLine("</body>"); wr.WriteLine("</html>"); wr.Close(); #endregion break; case 3: #region Gerar relatório dos agendamentos dos projetos que estão por vir wr = new StreamWriter(path + "relAgendProj.html"); wr.WriteLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/>"); wr.WriteLine("<html>"); wr.WriteLine("<head>"); wr.WriteLine("<meta name='viewport' content='width=device-width, initial-scale=1'>"); wr.WriteLine("<meta charset='utf-8'>"); wr.WriteLine("<link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>"); wr.WriteLine("<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js'></script>"); wr.WriteLine("<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script>"); wr.WriteLine("<div class='container'>"); wr.WriteLine("<h2>Relatório dos Agendamentos Futuros dos Projetos</h2>"); wr.WriteLine("<div class='table-responsive'>"); wr.WriteLine("<table class='table table-hover'>"); wr.WriteLine("<thead>"); wr.WriteLine("<tr>"); wr.WriteLine("<th>Código Projeto</th>"); wr.WriteLine("<th>Cliente</th>"); wr.WriteLine("<th>Endereço</th>"); wr.WriteLine("<th>Data Agendamento</th>"); wr.WriteLine("<th>Assunto Agendamento</th>"); wr.WriteLine("<th>Observação Agendamento</th>"); wr.WriteLine("</tr>"); wr.WriteLine("</thead>"); wr.WriteLine("</tbody>"); try { foreach (Agendamentos agend in agendDAO.select().Where(x => x.Data >= DateTime.Today && x.Projeto != null)) { wr.WriteLine("<tr><td>" + agend.Projeto.Id + "</td>"); try { Projetos projetos = projDAO.select().Where(x => x.Id == agend.Projeto.Id).First(); wr.WriteLine("<td>" + projetos.Cliente.Nome + "</td>"); } catch { } wr.WriteLine("<td>" + agend.Projeto.Endereco + "</td>"); wr.WriteLine("<td>" + agend.Data.ToString("dd/MM/yyyy") + "</td>"); wr.WriteLine("<td>" + agend.Assunto + "</td>"); wr.WriteLine("<td>" + agend.Observacao + "</td>"); } } catch { } wr.WriteLine("</tbody>"); wr.WriteLine("</table>"); wr.WriteLine("</div>"); wr.WriteLine("</div>"); wr.WriteLine("</body>"); wr.WriteLine("</html>"); wr.Close(); #endregion break; } }
public void AddFoto(Foto foto) { Fotos.Add(foto); }
protected override void Seed(FotoAppDB.FotoAppDbContext context) { #region price list context.Language.AddOrUpdate(a => a.Language, new Languages() { Language = "pl_PL", Base = null }); var shiny = context.TypeText.Where(a => a.Text == "B³yszcz¹cy").SingleOrDefault(); if (shiny == null) { shiny = new TypeTexts() { Types = new Types(), Text = "B³yszcz¹cy", Language = "pl_PL" } } ; var mat = context.TypeText.Where(a => a.Text == "Matowy").SingleOrDefault(); if (mat == null) { mat = new TypeTexts() { Types = new Types(), Text = "Matowy", Language = "pl_PL" } } ; context.TypeText.AddOrUpdate(shiny); context.TypeText.AddOrUpdate(mat); context.SaveChanges(); context.SizeText.AddOrUpdate(new SizeTexts() { Width = 900, Height = 1300, Text = "9x13", Language = "pl_PL", Sizes = new Sizes() { Width = 900, Height = 1300 } }); context.SizeText.AddOrUpdate(new SizeTexts() { Width = 1000, Height = 1500, Text = "10x15", Language = "pl_PL", Sizes = new Sizes() { Width = 1000, Height = 1500 } }); context.SizeText.AddOrUpdate(new SizeTexts() { Width = 1300, Height = 1800, Text = "13x18", Language = "pl_PL", Sizes = new Sizes() { Width = 1300, Height = 1800 } }); context.SizeText.AddOrUpdate(new SizeTexts() { Width = 1500, Height = 2100, Text = "15x21", Language = "pl_PL", Sizes = new Sizes() { Width = 1500, Height = 2100 } }); context.SizeText.AddOrUpdate(new SizeTexts() { Width = 1800, Height = 2400, Text = "18x24", Language = "pl_PL", Sizes = new Sizes() { Width = 1800, Height = 2400 } }); context.SizeText.AddOrUpdate(new SizeTexts() { Width = 2000, Height = 2500, Text = "20x25", Language = "pl_PL", Sizes = new Sizes() { Width = 2000, Height = 2500 } }); context.SizeText.AddOrUpdate(new SizeTexts() { Width = 2100, Height = 3000, Text = "21x30", Language = "pl_PL", Sizes = new Sizes() { Width = 2100, Height = 3000 } }); context.SizeText.AddOrUpdate(new SizeTexts() { Width = 2400, Height = 3000, Text = "24x30", Language = "pl_PL", Sizes = new Sizes() { Width = 2400, Height = 3000 } }); context.SaveChanges(); foreach (Types type in context.Type) { foreach (Sizes s in context.Size) { context.Paper.AddOrUpdate(new Papers() { Availability = null, Height = s.Height, TypeID = type.TypeID, Width = s.Width }); } } context.SaveChanges(); var t = mat; context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 1, Price = 100 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 11, Price = 70 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 51, Price = 65 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 101, Price = 60 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 201, Price = 55 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 301, Price = 53 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 401, Price = 51 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 501, Price = 49 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 1, Price = 100 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 11, Price = 80 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 51, Price = 75 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 101, Price = 70 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 201, Price = 66 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 301, Price = 63 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 401, Price = 61 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 501, Price = 59 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 1, Price = 160 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 51, Price = 150 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 101, Price = 140 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 201, Price = 130 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 301, Price = 120 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 401, Price = 110 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 501, Price = 100 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 1, Price = 200 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 51, Price = 180 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 101, Price = 160 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 201, Price = 150 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 301, Price = 140 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 401, Price = 130 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 501, Price = 120 }); context.Price.AddOrUpdate(new Prices() { Width = 1800, Height = 2400, TypeID = t.TypeID, Quantity = 1, Price = 500 }); context.Price.AddOrUpdate(new Prices() { Width = 2000, Height = 2500, TypeID = t.TypeID, Quantity = 1, Price = 600 }); context.Price.AddOrUpdate(new Prices() { Width = 2100, Height = 3000, TypeID = t.TypeID, Quantity = 1, Price = 800 }); context.Price.AddOrUpdate(new Prices() { Width = 2400, Height = 3000, TypeID = t.TypeID, Quantity = 1, Price = 1000 }); t = shiny; context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 1, Price = 100 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 11, Price = 70 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 51, Price = 65 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 101, Price = 60 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 201, Price = 55 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 301, Price = 53 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 401, Price = 51 }); context.Price.AddOrUpdate(new Prices() { Width = 900, Height = 1300, TypeID = t.TypeID, Quantity = 501, Price = 49 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 1, Price = 100 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 11, Price = 80 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 51, Price = 75 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 101, Price = 70 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 201, Price = 66 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 301, Price = 63 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 401, Price = 61 }); context.Price.AddOrUpdate(new Prices() { Width = 1000, Height = 1500, TypeID = t.TypeID, Quantity = 501, Price = 59 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 1, Price = 160 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 51, Price = 150 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 101, Price = 140 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 201, Price = 130 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 301, Price = 120 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 401, Price = 110 }); context.Price.AddOrUpdate(new Prices() { Width = 1300, Height = 1800, TypeID = t.TypeID, Quantity = 501, Price = 100 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 1, Price = 200 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 51, Price = 180 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 101, Price = 160 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 201, Price = 150 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 301, Price = 140 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 401, Price = 130 }); context.Price.AddOrUpdate(new Prices() { Width = 1500, Height = 2100, TypeID = t.TypeID, Quantity = 501, Price = 120 }); context.Price.AddOrUpdate(new Prices() { Width = 1800, Height = 2400, TypeID = t.TypeID, Quantity = 1, Price = 500 }); context.Price.AddOrUpdate(new Prices() { Width = 2000, Height = 2500, TypeID = t.TypeID, Quantity = 1, Price = 600 }); context.Price.AddOrUpdate(new Prices() { Width = 2100, Height = 3000, TypeID = t.TypeID, Quantity = 1, Price = 800 }); context.Price.AddOrUpdate(new Prices() { Width = 2400, Height = 3000, TypeID = t.TypeID, Quantity = 1, Price = 1000 }); #endregion Orders[] order = new Orders[10]; context.Order.RemoveRange(context.Order); for (int i = 0; i < 10; i++) { order[i] = new Orders() { Date = DateTime.Now }; context.Order.AddOrUpdate(order[i]); } context.SaveChanges(); Fotos[][] foto = new Fotos[10][]; for (int i = 0; i < 10; i++) { foto[i] = new Fotos[10]; } //var paper = context.Paper.ToList(); Random rand = new Random(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { foto[i][j] = new Fotos() { OrderID = order[i].OrderID, Name = order[i].ToString() + " " + j.ToString() }; context.Foto.AddOrUpdate(foto[i][j]); context.SaveChanges(); foreach (Papers p in context.Paper) { if (0 == rand.Next(0, 2)) { context.OrderFoto.AddOrUpdate(new OrderFotos() { FotoID = foto[i][j].FotoID, Height = p.Height, Width = p.Width, TypeID = p.TypeID, Quantity = rand.Next(1, 100) }); } } } } context.OrderFoto.AddOrUpdate(new OrderFotos() { Fotos = new Fotos() { Orders = new Orders() { Date = DateTime.Now }, Name = "test1" }, Height = 1800, Width = 1300, Quantity = 1, TypeID = mat.TypeID }); context.OrderFoto.AddOrUpdate(new OrderFotos() { Fotos = new Fotos() { Orders = new Orders() { Date = DateTime.Now }, Name = "test1" }, Height = 1800, Width = 1300, Quantity = 100000, TypeID = mat.TypeID }); TypeTexts[] tt = new TypeTexts[5]; for (int i = 0; i < 5; i++) { tt[i] = context.TypeText.Where(a => a.Text == "test" + i.ToString()).SingleOrDefault(); if (tt[i] == null) { tt[i] = new TypeTexts() { Types = new Types(), Text = "test" + i.ToString(), Language = "pl_PL" } } ; } context.SaveChanges(); List <Papers> paper = new List <Papers>(); foreach (Sizes s in context.Size) { for (int i = 0; i < 5; i++) { if (rand.Next(0, 1) == 0) { var p = new Papers() { Availability = rand.Next(50, 2000), Sizes = s, Types = tt[i].Types }; context.Paper.AddOrUpdate(p); paper.Add(p); } } } context.SaveChanges(); foreach (Papers p in paper) { for (int j = 0; j < rand.Next(4, 8); j++) { context.Price.AddOrUpdate(new Prices() { Height = p.Height, TypeID = p.TypeID, Width = p.Width, Price = 100 - j * 5, Quantity = j * 100 }); } } context.SaveChanges(); Orders[] ordert = new Orders[10]; for (int i = 0; i < 10; i++) { ordert[i] = new Orders() { Date = DateTime.Now }; context.Order.AddOrUpdate(ordert[i]); } context.SaveChanges(); Fotos[][] fotot = new Fotos[10][]; for (int i = 0; i < 10; i++) { fotot[i] = new Fotos[5]; } for (int i = 0; i < 10; i++) { for (int j = 0; j < 5; j++) { fotot[i][j] = new Fotos() { OrderID = ordert[i].OrderID, Name = ordert[i].ToString() + " " + j.ToString() }; context.Foto.AddOrUpdate(fotot[i][j]); context.SaveChanges(); foreach (Papers p in context.Paper) { if (0 == rand.Next(0, 1)) { context.OrderFoto.AddOrUpdate(new OrderFotos() { FotoID = fotot[i][j].FotoID, Height = p.Height, Width = p.Width, TypeID = p.TypeID, Quantity = rand.Next(1, 100) }); } } } } context.SaveChanges(); } } }
public ActionResult Create(List <HttpPostedFileBase> files, [Bind(Include = "AnimalID,EspecieFK,EstadoFK,DonoFK,Nome,Sexo,DataNasc,VistoQuando,Localidade,VistoOnde,Notas")] Animais animal) { if (ModelState.IsValid) { // gera o ID animal.AnimalID = Guid.NewGuid().ToString(); // atribui o 'dono' ao 'animal' animal.DonoFK = User.Identity.GetUserId(); // por defeito o estado será '1' = 'Desaparecido' animal.EstadoFK = "1"; // objeto 'dono' do 'animal' animal.Dono = db.Donos.Find(animal.DonoFK); // objeto 'estado' do 'animal' animal.Estado = db.Estados.Find(animal.EstadoFK); // objeto 'especie' do 'animal' animal.Especie = db.Especies.Find(animal.EspecieFK); foreach (var item in files) { if (item?.ContentLength > 0) { // verifica se o ficheiro submetido é uma imagem através do MIME Type string fileMIMEType = item.ContentType; if (fileMIMEType == "image/gif" || fileMIMEType == "image/png" || fileMIMEType == "image/jpeg") { // constrói a extensão do ficheiro string extension = "." + fileMIMEType.Substring(fileMIMEType.IndexOf("/") + 1); // constrói o caminho e o nome para o ficheiro string guid = Guid.NewGuid().ToString(); var path = Path.Combine(Server.MapPath("~/Content/Images/Animals"), guid + extension); // guarda o ficheiro no servidor item.SaveAs(path); // constrói o objeto 'foto' pertencente ao 'animal' Fotos foto = new Fotos { Animal = animal, AnimalFK = animal.AnimalID, FotoID = Guid.NewGuid().ToString(), Imagem = guid + extension }; // guarda o objeto 'foto' na lista de Fotos do 'animal' try { animal.Fotos.Add(foto); } catch (Exception) { // cria a mensagem de erro e redireciona para o controller que lida com os erros TempData["ErrorMessage"] = "Ocorreu um erro."; return(RedirectToAction("LastResource", "Account")); } } } } try { // guarda o registo do 'animal' na tabela 'Animais' da BD db.Animais.Add(animal); // torna as alterações persistentes db.SaveChanges(); } catch (Exception) { // cria a mensagem de erro e redireciona para o controller que lida com os erros TempData["ErrorMessage"] = "Ocorreu um erro."; return(RedirectToAction("LastResource", "Account")); } return(RedirectToAction("Index")); } ViewBag.EspecieFK = new SelectList(db.Especies, "EspecieID", "Descricao", animal.EspecieFK); return(View(animal)); }