public ResponseModel Guardar() { var rm = new ResponseModel(); try { using (var ctx = new ProyectoContext()) { if (this.id > 0) { ctx.Entry(this).State = EntityState.Modified; } else { ctx.Entry(this).State = EntityState.Added; } ctx.SaveChanges(); rm.SetResponse(true); } } catch (Exception) { throw; } return(rm); }
public ResponseModel Guardar() { var rm = new ResponseModel(); Servicio serv = new Servicio(); try { using (var ctx = new ProyectoContext()) { if (this.idservicio > 0) { ctx.Entry(this).State = EntityState.Modified; } else { ctx.Entry(this).State = EntityState.Added; //var idultimo = } 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()) { if (id > 0) { this.id = id; ctx.Entry(this).State = EntityState.Deleted; ctx.SaveChanges(); rm.SetResponse(true); } } } catch (Exception e) { throw e; } return(rm); }
public ResponseModel Guardar(HttpPostedFileBase Foto) { var rm = new ResponseModel(); try { using (var ctx = new ProyectoContext()) { //validaciones esten desabilitadas ctx.Configuration.ValidateOnSaveEnabled = false; var eUsuario = ctx.Entry(this); eUsuario.State = EntityState.Modified; //Campos que queremos ignorar if (this.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); //Ruta donde lo vamos a 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) { throw; } catch (Exception) { throw; } return(rm); }
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); }