public void Eliminar() { try { using (var ctx = new ProyectoContext()) { ctx.Entry(this).State = EntityState.Deleted; ctx.SaveChanges(); } } catch (Exception E) { throw; } }
//Para HttpPostedFileBase: Se agrego Proyecto Model la referencia desde Assembly Sysmtem.Web public ResponseModel Guardar(HttpPostedFileBase Foto, String Password) { ResponseModel rm = new ResponseModel(); try { using (var ctx = new ProyectoContext()) { ctx.Configuration.ValidateOnSaveEnabled = false; var usr = ctx.Entry(this); usr.State = EntityState.Modified; if (this.Foto != null) { string archivo = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(Foto.FileName); Foto.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads" + archivo)); this.Foto = archivo; } else { usr.Property(x => x.Foto).IsModified = false; } if (this.Password == null) { usr.Property(x => x.Password).IsModified = false; } else { this.Password = Helper.HashHelper.MD5(Password); } ctx.SaveChanges(); rm.SetResponse(true); } } catch (DbEntityValidationException e) { throw e; } catch (Exception e) { throw e; } return(rm); }
public ResponseModel Guardar(HttpPostedFileBase Foto) { var rm = new ResponseModel(); try { using (var ctx = new ProyectoContext()) { ctx.Configuration.ValidateOnSaveEnabled = false; var eUsuario = ctx.Entry(this); eUsuario.State = EntityState.Modified; // Campos que queremos ignorar if (Foto != null) { // Nombre del archivo, es decir, lo renombramos para que no se repita nunca string archivo = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(Foto.FileName); // La ruta donde lo vamos guardar Foto.SaveAs(HttpContext.Current.Server.MapPath("~/uploads/" + archivo)); // Establecemos en nuestro modelo el nombre del archivo this.Foto = archivo; } else eUsuario.Property(x => x.Foto).IsModified = false; if (this.Password == null) eUsuario.Property(x => x.Password).IsModified = false; ctx.SaveChanges(); rm.SetResponse(true); } } catch (DbEntityValidationException e) { throw; } catch (Exception) { throw; } return rm; }
public ResponseModel Guardar() { var rm = new ResponseModel(); try { using (var ctx = new ProyectoContext()) { ctx.Entry(this).State = EntityState.Added; rm.SetResponse(true); ctx.SaveChanges(); } } catch (Exception E) { throw; } return(rm); }
public ResponseModel Eliminar(int id) { var rm = new ResponseModel(); try { using (var ctx = new ProyectoContext()) { this.id = id; ctx.Entry(this).State = EntityState.Deleted; ctx.SaveChanges(); rm.SetResponse(true); } } catch (Exception ex) { throw; } return(rm); }