public ActionResult DeleteConfirmed(int id) { COMPONENTE cOMPONENTE = db.COMPONENTE.Find(id); db.COMPONENTE.Remove(cOMPONENTE); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Agregar nuevo dispositivo. /// </summary> /// <param name="dispositivo">Objeto dispositivo del modelo DispositivosModel.</param> /// <returns></returns> internal RespuestaBase AgregarDispositivo(DispositivosModel dispositivo) { log.Info("Llamada al metodo"); RespuestaBase respuesta = new RespuestaBase(); try { dispositivo.registro = dispositivo.registro != null ? dispositivo.registro : DateTime.Now; DISPOSITIVO new_dispositivo = BaseModel.GetModel <DISPOSITIVO>(dispositivo, new DISPOSITIVO()); DispositivosRepository.AgregarDispositivo(new_dispositivo); if (new_dispositivo.id != 0) { dispositivo.id = new_dispositivo.id; respuesta.Datos = dispositivo; if (dispositivo.Componentes.Count > 0) { foreach (ComponentesModel componenete in dispositivo.Componentes) { COMPONENTE new_componenete = BaseModel.GetModel <COMPONENTE>(componenete, new COMPONENTE()); if (new_componenete.nombre != null) { try { new_componenete.registro = DateTime.Now; new_componenete.dispositivo_id = new_dispositivo.id; ComponentesRepository.AgregarComponente(new_componenete); componenete.registro = new_componenete.registro; componenete.id = new_componenete.id; componenete.dispositivo_id = new_dispositivo.id; } catch (Exception ex) { respuesta.Mensaje += " " + ex.Message; log.Error(respuesta.Mensaje, ex); } } } } } else { string mensaje = String.Format("No fue posible agregar nuevo dispositivo nombre-->{0}.", dispositivo.nombre); respuesta.Estatus = false; respuesta.Mensaje += " " + mensaje; log.Error(mensaje); } } catch (Exception ex) { respuesta.Mensaje += " " + ex.Message; respuesta.Estatus = false; log.Error(respuesta.Mensaje, ex); } return(respuesta); }
public ActionResult Edit([Bind(Include = "idComponente,ramTotal,ramDispo,usoCpu")] COMPONENTE cOMPONENTE) { if (ModelState.IsValid) { db.Entry(cOMPONENTE).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cOMPONENTE)); }
protected void dsComponente_Selected(object sender, ObjectDataSourceStatusEventArgs e) { List<COMPONENTE> lista = (List<COMPONENTE>)e.ReturnValue; if (lista.Count == 0) { COMPONENTE componente = new COMPONENTE(); componente.COM_NOMBRE = ""; lista.Add(componente); } }
public ActionResult Create([Bind(Include = "idComponente,ramTotal,ramDispo,usoCpu")] COMPONENTE cOMPONENTE) { if (ModelState.IsValid) { db.COMPONENTE.Add(cOMPONENTE); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cOMPONENTE)); }
// GET: Componentes/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } COMPONENTE cOMPONENTE = db.COMPONENTE.Find(id); if (cOMPONENTE == null) { return(HttpNotFound()); } return(View(cOMPONENTE)); }
protected void imgAgregar_Click(object sender, ImageClickEventArgs e) { try { using (FileUpload uplComponente = ((FileUpload)this.grvComponente.FooterRow.FindControl("uplComponenteFooter"))) { if (uplComponente.HasFile) { string fileName = uplComponente.FileName; if (Path.GetExtension(fileName).ToUpper() != ".DLL") { this.lblMensaje.Text = "No es un archivo válido."; return; } COMPONENTE componente = new COMPONENTE() { COM_NOMBRE = ((TextBox)this.grvComponente.FooterRow.FindControl("txtNombreFooter")).Text, COM_ARCHIVO = Path.GetFileName(fileName) }; EstadoOperacion resultado = ComponenteBL.insertarComponente(componente); if (resultado.Estado) { string directorio = DllDinamica.DirectorioComponentes(); uplComponente.SaveAs(directorio + Path.GetFileName(fileName)); this.grvComponente.DataBind(); } else { this.lblMensaje.Text = resultado.Mensaje; } } } } catch (Exception ex) { this.lblMensaje.Text = ex.Message; } }
/// <summary> /// Agrega nuevo componente. /// </summary> /// <param name="new_componente">Nuevo objeto componente de la tabla COMPONENTES</param> /// <returns></returns> internal static COMPONENTE AgregarComponente(COMPONENTE new_componente) { log.Info("Llamada al metodo"); using (play0dbEntities dbEntities = new play0dbEntities()) { COMPONENTE existe_componente = dbEntities.COMPONENTES.Where(x => x.nombre == new_componente.nombre && x.dispositivo_id == new_componente.dispositivo_id).Select(s => s).FirstOrDefault(); if (existe_componente != null) { throw new ArgumentException(string.Format("Ya existe un componente con el nombre {0} en el dispositovo con ID {1}.", new_componente.nombre, new_componente.dispositivo_id.ToString())); } dbEntities.COMPONENTES.Add(new_componente); dbEntities.SaveChanges(); if (new_componente.id != 0) { return(new_componente); } else { throw new Exception(string.Format("No fue posible guardar un nuevo componente {0}.", new_componente.nombre)); } } }
private void ModificarComponente(int index) { try { GridViewRow row = this.grvComponente.Rows[index]; using (FileUpload uplComponente = ((FileUpload)row.FindControl("uplComponenteEdit"))) { string fileName = uplComponente.FileName; if (Path.GetExtension(fileName).ToUpper() != ".DLL") { this.lblMensaje.Text = "No es un archivo válido."; return; } COMPONENTE componente = new COMPONENTE() { COM_CODIGO = int.Parse(this.grvComponente.DataKeys[index].Values["COM_CODIGO"].ToString()), COM_NOMBRE = string.Empty, COM_ARCHIVO = Path.GetFileName(fileName) }; EstadoOperacion resultado = ComponenteBL.modificarComponente(componente); if (resultado.Estado) { string rutaArchivoNuevo = Path.GetFileName(fileName); string rutaArchivoViejo = this.grvComponente.DataKeys[index].Values["COM_ARCHIVO"].ToString(); string directorio = DllDinamica.DirectorioComponentes(); FileInfo archivoViejo = new FileInfo(directorio + rutaArchivoViejo); { if (archivoViejo.Exists) { archivoViejo.Delete(); } } uplComponente.SaveAs(directorio + rutaArchivoNuevo); grvComponente.EditIndex = -1; this.grvComponente.DataBind(); } else { this.lblMensaje.Text = resultado.Mensaje; } } } catch (Exception ex) { this.lblMensaje.Text = ex.Message; } }
private void EliminarComponente(int index) { try { COMPONENTE componente = new COMPONENTE() { COM_CODIGO = int.Parse(this.grvComponente.DataKeys[index].Values["COM_CODIGO"].ToString()), }; EstadoOperacion resultado = ComponenteBL.eliminarComponente(componente); if (resultado.Estado) { string rutaArchivoViejo = this.grvComponente.DataKeys[index].Values["COM_ARCHIVO"].ToString(); string directorio = ConfigurationManager.AppSettings["DirectorioComponentes"]; FileInfo archivoViejo = new FileInfo(directorio + rutaArchivoViejo); { if (archivoViejo.Exists) { archivoViejo.Delete(); } } this.grvComponente.DataBind(); } else { this.lblMensaje.Text = resultado.Mensaje; } } catch (Exception ex) { this.lblMensaje.Text = ex.Message; } }