public obras FindIdObra(string obra) { obras ob = new obras(); ob = _db.obras.Where(o => o.Nombre == obra).FirstOrDefault(); return(ob); }
public List <equipos> FindEquiposPorObra(int?id) { obras ob = new obras(); fallas fa = new fallas(); //fa = _db.fallas.Where(f => f.Id == id).FirstOrDefault(); //ob = _db.obras.Where(o => o.Nombre == fa.Obra).FirstOrDefault(); //if (ob != null) { return(_db.equipos.Where(o => o.obra_id == id).ToList()); //} // else //{ // return null; //} }
//public CuentaConUsuarioMaestro FindWithUsuarioMaestro(int id) //{ // var query = (from c in _db.cuentas // from u in c.aspnetusers1 // where u.Tipo == UsuarioManager.Tipo.MaestroProveedor // && c.Id == id // select new CuentaConUsuarioMaestro { Cuenta = c, UsuarioMaestro = u }); // return query.FirstOrDefault(); //} public obras Crear(string nombre = null, string personajuridica = null, string direccionfacturacion = null, string direccionoficina = null, string direccionobra = null, string telefonooficina = null, string contacto = null, string contacto2 = null , string email = null, string email2 = null, string foto = null, string mapa = null) { try { var obra = new obras() { Nombre = nombre, PersonaJuridica = personajuridica, DireccionFacturacion = direccionfacturacion, DireccionOficina = direccionoficina, DireccionObra = direccionobra, TelefonoOficina = telefonooficina, Contacto = contacto, Contacto2 = contacto2, Email = email, Email2 = email2, foto = foto, mapa = mapa }; var id = _db.obras.Add(obra); _db.SaveChanges(); var ascensorprivado = new equipos() { Nombre = "ASCENSOR PRIVADO", obra_id = id.Id }; var idequipoap = _db.equipos.Add(ascensorprivado); _db.SaveChanges(); var previo = new previos() { FechaFirmaContrato = DateTime.Now, FechaPagoInicialFabrica = DateTime.Now, FechaPagoInicialEquipo = DateTime.Now, FechaConstruccion = DateTime.Now, FechaSalidaFabrica = DateTime.Now, FechaSalidaBuque = DateTime.Now, FechaLlegadaBuque = DateTime.Now, FechaPeriodoNacionalizacion = DateTime.Now, FechaSalidaPuertoObra = DateTime.Now, FechaDescargaResguardo = DateTime.Now, ActivacionProtocoloGarantiaFabrica = "no", FechaInicioMontaje = DateTime.Now, FechaEntregaSoso = DateTime.Now, FechaCulminacionMontaje = DateTime.Now, FechaConfiguracion = DateTime.Now, FechaPeriodoPrueba = DateTime.Now, FechaInspeccion = DateTime.Now, equipo_id = idequipoap.Id }; _db.previos.Add(previo); _db.SaveChanges(); /* var ascensorservicio = new equipos() * { * * Nombre = "ASCENSOR DE SERVICIO", * obra_id = id.Id * * }; * var idequipoas = _db.equipos.Add(ascensorservicio); * _db.SaveChanges(); * * var previoas = new previos() * { * equipo_id = idequipoas.Id * }; * var previo_id = _db.previos.Add(previoas); * _db.SaveChanges();*/ var protocolo = new protocolos() { obra_id = id.Id, IdPrevio = previo.Id }; _db.protocolos.Add(protocolo); _db.SaveChanges(); /*var herramienta = new herramientas() * { * obra_id = id.Id, * previo_id = previo.Id * }; * _db.herramientas.Add(herramienta); * _db.SaveChanges();*/ /* * var montacarro = new equipos() * { * * Nombre = "MONTA CARRO", * obra_id = id.Id * * }; * var idequipomc = _db.equipos.Add(montacarro); * _db.SaveChanges(); * * var previomc = new previos() * { * equipo_id = idequipomc.Id * }; * _db.previos.Add(previomc); * _db.SaveChanges(); */ var ventamanprev = new ventas() { Descripcion = "MANTENIMIENTOS PREVENTIVOS", IdObra = id.Id }; var idventamp = _db.ventas.Add(ventamanprev); _db.SaveChanges(); var ventamancorrec = new ventas() { Descripcion = "MANTENIMIENTOS CORRECTIVOS", IdObra = id.Id }; var idventamc = _db.ventas.Add(ventamancorrec); _db.SaveChanges(); var ventainfor = new ventas() { Descripcion = "INFORMES GENERALES", IdObra = id.Id }; var idventainforme = _db.ventas.Add(ventainfor); _db.SaveChanges(); var ventarepo = new ventas() { Descripcion = "REPORTES DE SUGERENCIAS", IdObra = id.Id }; var idventasugerencia = _db.ventas.Add(ventarepo); _db.SaveChanges(); var mp = new mantenimientopreventivo() { IdVenta = idventamp.Id }; _db.mantenimientopreventivo.Add(mp); _db.SaveChanges(); var mc = new mantenimientocorrectivo() { IdVenta = idventamc.Id }; _db.mantenimientocorrectivo.Add(mc); _db.SaveChanges(); var informe = new informes() { IdVenta = idventainforme.Id, Url = "null", Nombre = "null", Fecha = DateTime.Now }; _db.informes.Add(informe); _db.SaveChanges(); var sugerencia = new sugerencias() { IdVenta = idventasugerencia.Id, Descripcion = "null", Caracteristica = "null", Numero = "null", AccionesRecomendadas = "null", AccionesTomadas = "null", GerenciaResponsable = "null", Fecha = DateTime.Now }; _db.sugerencias.Add(sugerencia); _db.SaveChanges(); return(id); } catch (Exception) { throw; } }
public ActionResult Crear(ComponenteMecanicoViewModel model, FormCollection collection) { var Url = ""; var pdfUrl = ""; ViewBag.obra = _obrasManager.Find(Convert.ToInt32(TempData["obra"])); TempData.Keep(); if (!ModelState.IsValid) { return(View(model)); } try { /* HttpPostedFileBase pdf = Request.Files["Pdf"]; * * if (pdf != null && pdf.ContentLength > 0) * { * pdfUrl = CargarPdf(pdf); * } * else { pdfUrl = ""; } */ obras obra = _obrasManager.Find(Convert.ToInt32(TempData["obra"])); equipos equipo = _equiposManager.Find(Convert.ToInt32(TempData["equipo"])); componentesmecanicos cm = _componentesmecanicosManager.Crear(Convert.ToInt32(TempData["equipo"]), model.Tipo, model.Caracteristicas, model.Descripcion, model.Marca, model.Modelo, model.Serial, model.FechaFabricado, model.Duracion, model.Sustitucion, pdfUrl.Trim(), model.FechaSustitucion, model.FechaAlerta, obra.Nombre, equipo.Nombre); TempData.Keep(); HttpPostedFileBase file; for (int i = 0; i < Request.Files.Count; i++) { file = Request.Files[i]; var d = Request.Files.AllKeys[i].ToString(); if (d == "Pdf" && file.FileName != "") { Url = CargarPdf(file); _obrasManager.AgregarArchivos(cm.Id, Url, "componentesmecanicos", "fotografia"); } } //TempData["FlashSuccess"] = MensajesResource.INFO_MensajesInstitucionales_CreadoCorrectamente; return(RedirectToAction("ComponentesMecanicos", "AdministrarComponentesMecanicos", new { @id = TempData["equipo"] })); } catch (BusinessException businessEx) { ModelState.AddModelError(string.Empty, businessEx.Message); return(View(model)); } catch (Exception e) { var log = CommonManager.BuildMessageLog( TipoMensaje.Error, ControllerContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString(), ControllerContext.Controller.ValueProvider.GetValue("action").RawValue.ToString(), e.ToString(), Request); CommonManager.WriteAppLog(log, TipoMensaje.Error); ModelState.AddModelError(string.Empty, e.Message); return(View(model)); } }
public ActionResult Crear(ObraViewModel model, FormCollection collection) { var Url = ""; var fotoMapa = ""; if (!ModelState.IsValid) { return(View(model)); } try { /*HttpPostedFileBase file_foto = Request.Files["file-foto"]; * * HttpPostedFileBase file_mapa = Request.Files["file-mapa"]; * * if (file_foto != null && file_foto.ContentLength > 0) * { * fotoUrl = CargarPdf(file_foto); * } * else { fotoUrl = ""; } * if (file_mapa != null && file_mapa.ContentLength > 0) * { * fotoMapa = CargarPdf(file_mapa); * } * else { fotoMapa = ""; } */ obras obra = _obrasManager.Crear( model.Nombre, model.PersonaJuridica, model.DireccionFacturacion, model.DireccionOficina, model.DireccionObra, model.TelefonoOficina, model.Contacto, model.Contacto2, model.Email, model.Email2, "", ""); _obrasManager.AgregarArchivos(obra.Id, model.mapa, "obras", "mapa"); HttpPostedFileBase file; for (int i = 0; i < Request.Files.Count; i++) { file = Request.Files[i]; var d = Request.Files.AllKeys[i].ToString(); if (d == "Pdf-Fotografia" && file.FileName != "") { Url = CargarPdf(file); _obrasManager.AgregarArchivos(obra.Id, Url, "obras", "fotografia"); } if (d == "Pdf-Mapa" && file.FileName != "") { Url = CargarPdf(file); _obrasManager.AgregarArchivos(obra.Id, Url, "obras", "mapa"); } } TempData["FlashSuccess"] = MensajesResource.INFO_Obras_CreadoCorrectamente; return(RedirectToAction("Index")); } catch (BusinessException businessEx) { ModelState.AddModelError(string.Empty, businessEx.Message); return(View(model)); } catch (Exception e) { var log = CommonManager.BuildMessageLog( TipoMensaje.Error, ControllerContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString(), ControllerContext.Controller.ValueProvider.GetValue("action").RawValue.ToString(), e.ToString(), Request); CommonManager.WriteAppLog(log, TipoMensaje.Error); ModelState.AddModelError(string.Empty, e.Message); return(View(model)); } }