public ResponseModel Acceder(string Email, string Password) { var rm = new ResponseModel(); try { using (var ctx = new Portafolio()) { Password = HashHelper.MD5(Password); var usuario = ctx.Usuario.Where(x => x.Email == Email) .Where(x => x.Password == Password) .SingleOrDefault(); if (usuario != null) { SessionHelper.AddUserToSession(usuario.id.ToString()); rm.SetResponse(true); } else { rm.SetResponse(false, "Correo o Contraseña incorrecta"); } } } catch (Exception exception) { throw; } return(rm); }
public ResponseModel Guardar(HttpPostedFileBase Foto) { var rm = new ResponseModel(); try { using (var ctx = new Portafolio()) { 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.GetFileName(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; } if (Password == null) { eUsuario.Property(x => x.Password).IsModified = false; } ctx.SaveChanges(); rm.SetResponse(true); } } catch (DbEntityValidationException e) { throw; } catch (Exception exception) { throw; } return(rm); }
public List <TablaDato> Listar(string relacion) { var datos = new List <TablaDato>(); try { using (var ctx = new Portafolio()) datos = ctx.TablaDato.OrderBy(x => x.Orden) .Where(x => x.Relacion == relacion) .ToList(); } catch (Exception exception) { throw; } return(datos); }
public Usuario Obtener(int id) { var usuario = new Usuario(); try { using (var ctx = new Portafolio()) { usuario = ctx.Usuario.Where(x => x.id == id) .SingleOrDefault(); } } catch (Exception exception) { throw; } return(usuario); }