public ActionResult Create([Bind(Include = "idequipo,ubicacion_fk,tipo_de_equipo_fk,marca_modelo_fk,s_equipo_numero_serie,descripcion,altura_u,prof_inch,es_contenedor,s_equipo_fecha_configuracion,responsable_fk,es_propio,comentarios,path_imagen,es_activo,es_virtual,proveedor_fk,atributo_por_equipo")] equipo equipo) { if (ModelState.IsValid) { db.equipo.Add(equipo); db.SaveChanges(); /*Software por equipo*/ if (TempData["spe"] != null) { foreach (software_por_equipo _spe in (List <software_por_equipo>)TempData["spe"]) { software_por_equipo newItem = new software_por_equipo(); newItem.software = null; newItem.software_fk = _spe.software_fk; newItem.equipo_fk = equipo.idequipo; newItem.observaciones = _spe.observaciones; db.software_por_equipo.Add(newItem); } } /*Puerto por equipo*/ if (TempData["ppe"] != null) { foreach (puerto_por_equipo _ppe in (List <puerto_por_equipo>)TempData["ppe"]) { puerto_por_equipo newItem = new puerto_por_equipo(); newItem.puerto = null; newItem.puerto_fk = _ppe.puerto_fk; newItem.equipo_fk = equipo.idequipo; newItem.numero_de_puertos = _ppe.numero_de_puertos; db.puerto_por_equipo.Add(newItem); } } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.marca_modelo_fk = new SelectList(db.marca_modelo, "idmarca_modelo", "marca_modelo_string", equipo.marca_modelo_fk); ViewBag.proveedor_fk = new SelectList(db.proveedor, "idproveedor", "nombre_comercial", equipo.proveedor_fk); ViewBag.responsable_fk = new SelectList(db.responsable, "idresponsable", "cedula_ruc", equipo.responsable_fk); ViewBag.tipo_de_equipo_fk = new SelectList(db.tipo_de_equipo, "idtipo_de_equipo", "categoria", equipo.tipo_de_equipo_fk); ViewBag.ubicacion_fk = new SelectList(db.ubicacion, "idubicacion", "nombre", equipo.ubicacion_fk); ViewBag.listaAtributos = (List <Inventario.Models.atributo>)db.atributo.ToList(); SetRegExDictionary(); return(View(equipo)); }
public ActionResult EditingInline_Update_Puerto([DataSourceRequest] DataSourceRequest request, puerto_por_equipo soft) { List <puerto_por_equipo> pCache; cloudmanageEntities ent = new cloudmanageEntities(); if (soft != null && ModelState.IsValid) { // pes.Update(soft); if (soft.puerto_fk > 0) { soft.puerto_nombre = ent.puerto.Where(s => s.idpuerto == soft.puerto_fk).Select(s => s.nombre).First(); } else { soft.puerto_nombre = ""; } // Add new item bool isPrex = false; pCache = (List <puerto_por_equipo>)TempData["ppe"]; TempData["ppe"] = pCache; for (int i = 0; i < pCache.Count; i++) { if (pCache[i].puerto_fk == soft.puerto_fk) { pCache[i] = soft; // Replace updated item. isPrex = true; } } TempData["ppe"] = pCache; if (!isPrex) { pCache = (List <puerto_por_equipo>)TempData["ppe"]; pCache.Add(soft); TempData["ppe"] = pCache; } else // Update fields { } } return(Json(new[] { soft }.ToDataSourceResult(request, ModelState))); }
public ActionResult EditingInline_Destroy_Puerto([DataSourceRequest] DataSourceRequest request, puerto_por_equipo soft) { List <puerto_por_equipo> pCache; //PopulateSoftware(); if (soft != null) { pCache = (List <puerto_por_equipo>)TempData["ppe"]; puerto_por_equipo pxe_todelete = null; // Find item to be removed foreach (puerto_por_equipo pxeitem in pCache) { if (pxeitem.equipo_fk == soft.equipo_fk && pxeitem.puerto_fk == soft.puerto_fk) { pxe_todelete = pxeitem; pxe_todelete.numero_de_puertos = "DELETED"; } } //if (sxe_todelete != null) //{ // pCache.Remove(sxe_todelete); //} TempData["ppe"] = pCache; pes.Destroy(soft); } return(Json(new[] { soft }.ToDataSourceResult(request, ModelState))); }
public ActionResult EditingInline_Create_Puerto([DataSourceRequest] DataSourceRequest request, puerto_por_equipo soft) { List <puerto_por_equipo> pCache; cloudmanageEntities ent = new cloudmanageEntities(); if (soft != null && ModelState.IsValid) { // Update internal field for software_fk if (Int32.TryParse(soft.puerto_nombre, out int tval)) { soft.puerto_fk = tval; } // If valid puerto_fk update puerto_nombre if (soft.puerto_fk > 0) { soft.puerto_nombre = ent.puerto.Where(s => s.idpuerto == soft.puerto_fk). Select(s => s.nombre).First(); } else { soft.puerto_nombre = ""; soft.puerto = null; } // Add new item bool isPrex = false; pCache = (List <puerto_por_equipo>)TempData["ppe"]; TempData["ppe"] = pCache; foreach (puerto_por_equipo sspe in pCache) { if (sspe.puerto_fk == soft.puerto_fk) { isPrex = true; } } if (!isPrex) { pCache = (List <puerto_por_equipo>)TempData["ppe"]; pCache.Add(soft); TempData["ppe"] = pCache; } } return(Json(new[] { soft }.ToDataSourceResult(request, ModelState))); }
public ActionResult Edit([Bind(Include = "idequipo,ubicacion_fk,tipo_de_equipo_fk,marca_modelo_fk,s_equipo_numero_serie,descripcion,altura_u,prof_inch,es_contenedor,s_equipo_fecha_configuracion,responsable_fk,es_propio,comentarios,path_imagen,es_activo,es_virtual,proveedor_fk,atributo_por_equipo")] equipo equipo) { ViewBag.softwares = new SelectList(db.software, "idsoftware", "nombre"); ViewBag.puertos = new SelectList(db.puerto, "idpuerto", "nombre"); ViewBag.listaAtributos = (List <Inventario.Models.atributo>)db.atributo.ToList(); SetRegExDictionary(); if (ModelState.IsValid) { using (var dbDinamo = new cloudmanageEntities()) { foreach (atributo_por_equipo ar in equipo.atributo_por_equipo) { if (dbDinamo.atributo_por_equipo.Find(ar.atributo_fk, ar.equipo_fk) != null) { db.Entry(ar).State = EntityState.Modified; } else { db.Entry(ar).State = EntityState.Added; } } } db.Entry(equipo).State = EntityState.Modified; db.SaveChanges(); /*Software por equipo*/ if (TempData["spe"] != null) { using (var dbDinamo = new cloudmanageEntities()) { foreach (software_por_equipo _spe in (List <software_por_equipo>)TempData["spe"]) { if (dbDinamo.software_por_equipo.Find(_spe.equipo_fk, _spe.software_fk) != null) { _spe.equipo = null; _spe.software = null; if (_spe.observaciones == "DELETED") { db.Entry(_spe).State = EntityState.Deleted; } else { db.Entry(_spe).State = EntityState.Modified; } } else { software_por_equipo newItem = new software_por_equipo(); newItem.software = null; newItem.software_fk = _spe.software_fk; newItem.equipo_fk = equipo.idequipo; newItem.observaciones = _spe.observaciones; db.Entry(newItem).State = EntityState.Added; } } } } /*Puerto por equipo*/ if (TempData["ppe"] != null && ((List <puerto_por_equipo>)TempData["ppe"]).Count > 0) { using (var dbDinamo = new cloudmanageEntities()) { foreach (puerto_por_equipo _ppe in (List <puerto_por_equipo>)TempData["ppe"]) { if (dbDinamo.puerto_por_equipo.Find(_ppe.equipo_fk, _ppe.puerto_fk) != null) { _ppe.equipo = null; _ppe.puerto = null; if (_ppe.numero_de_puertos == "DELETED") { db.Entry(_ppe).State = EntityState.Deleted; } else { db.Entry(_ppe).State = EntityState.Modified; } } else { puerto_por_equipo newItem = new puerto_por_equipo(); newItem.puerto = null; newItem.puerto_fk = _ppe.puerto_fk; newItem.equipo_fk = equipo.idequipo; newItem.numero_de_puertos = _ppe.numero_de_puertos; db.Entry(newItem).State = EntityState.Added; } } } } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.marca_modelo_fk = new SelectList(db.marca_modelo, "idmarca_modelo", "marca_modelo_string", equipo.marca_modelo_fk); ViewBag.proveedor_fk = new SelectList(db.proveedor, "idproveedor", "nombre_comercial", equipo.proveedor_fk); ViewBag.responsable_fk = new SelectList(db.responsable, "idresponsable", "cedula_ruc", equipo.responsable_fk); ViewBag.tipo_de_equipo_fk = new SelectList(db.tipo_de_equipo, "idtipo_de_equipo", "categoria", equipo.tipo_de_equipo_fk); ViewBag.ubicacion_fk = new SelectList(db.ubicacion, "idubicacion", "nombre", equipo.ubicacion_fk); return(View(equipo)); }