public ResponseModel Guardar() { var rm = new ResponseModel(); try { using (var ctx = new PortafolioModel()) { var Habilidad = ctx.Entry(this); if (this.id > 0) { Habilidad.State = EntityState.Modified; } else { Habilidad.State = EntityState.Added; } ctx.SaveChanges(); rm.SetResponse(true); } } catch (Exception) { throw; } return(rm); }
public ResponseModel Guardar(HttpPostedFileBase foto) { var rm = new ResponseModel(); try { using (var ctx = new PortafolioModel()) { ctx.Configuration.ValidateOnSaveEnabled = false; var eUsuario = ctx.Entry(this); eUsuario.State = EntityState.Modified; if (foto != null) { string archivo = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(foto.FileName); foto.SaveAs(HttpContext.Current.Server.MapPath("~/uploads/" + 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) { } catch (Exception) { throw; } return(rm); }
public ResponseModel Eliminar(int id) { var rm = new ResponseModel(); try { using (var ctx = new PortafolioModel()) { var Habilidad = ctx.Habilidads.Where(x => x.id == id).FirstOrDefault(); var entry = ctx.Entry(Habilidad); entry.State = EntityState.Deleted; ctx.SaveChanges(); rm.SetResponse(true); } } catch (Exception) { throw; } return(rm); }