public async Task <IHttpActionResult> Register(DTO.Usuario userModel) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var usuario = await _repo.FindUser(userModel.NickName, userModel.Password); if (usuario == null) { IdentityResult result = await _repo.RegisterUser(userModel); IHttpActionResult errorResult = GetErrorResult(result); if (errorResult != null) { return(errorResult); } } return(Ok(true)); } catch (Exception err) { return(BadRequest("Fallo " + err.Message)); } }
public void Insert(DTO.Usuario dto, string password) { var db = Map.Get <DAL.DTO.Usuario>(dto); db.Id = Guid.NewGuid(); db.Password = password; db.Logo = dto.Sexo == 'M' ? "man.png" : "woman.png"; this.Session.Usuario.UpsertEntity(db); this.Session.Commit(); }
public YerbaSoft.DTO.Result <DTO.Usuario> Update(DTO.Usuario dto) { try { var db = this.Session.Usuario.Find(p => p.Id == dto.Id).Single(); Map.CopyTo(dto, db); this.Session.Usuario.UpsertEntity(db); this.Session.Commit(); return(new YerbaSoft.DTO.Result <DTO.Usuario>(Map.Get <DTO.Usuario>(db))); } catch (Exception ex) { return(new YerbaSoft.DTO.Result <DTO.Usuario>(ex)); } }
internal static DAL.DTO.Usuario ConvertToDAL(DTO.Usuario item) { DAL.DTO.Usuario user = null; if (item != null) { user = new DAL.DTO.Usuario { Id = item.Id, Nombre = item.Nombre, Identity_Code = item.Identity_Code, Password = item.Password }; } return(user); }
public async Task <IHttpActionResult> UpdateUserAsync(DTO.Usuario usuario) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _repo.UpdateUser(usuario); if (result != null) { return(Ok(true)); } else { return(BadRequest()); } }
public async Task <IHttpActionResult> ChangePassword(DTO.UsuarioPassword usuarioPassword) { try { string usuarioId = DbContextAIVH.GetUserName(User); AccountController accountController = new AccountController(); IHttpActionResult result = await accountController.FindUser(usuarioId, usuarioPassword.password); if (result is OkNegotiatedContentResult <bool> status) { if (usuarioPassword.newPassword != usuarioPassword.confirmPassword) { return(BadRequest("El nuevo password y su confirmación no son iguales.")); } DTO.Usuario usuario = new DTO.Usuario { NickName = usuarioId, Password = usuarioPassword.newPassword }; result = await accountController.UpdateUserAsync(usuario); if (result is OkNegotiatedContentResult <bool> status2) { return(Ok("Cambio de password correcto. <br/><br/> Es necesario iniciar sesión nuevamente")); } else { return(BadRequest("Error al cambiar password.")); } } else { return(BadRequest("El password actual es incorrecto.")); } } catch (Exception Ex) { return(BadRequest("Error al cambiar password.")); } }
public int DeletaUsuario(DTO.Usuario USU) { try { SqlConnection CON = new SqlConnection(); CON.ConnectionString = Properties.Settings.Default.CST; SqlCommand CM = new SqlCommand(); CM.CommandType = System.Data.CommandType.Text; CM.CommandText = "DELETE Usuario WHERE Id_Nome = @Id_Nome"; CM.Parameters.Add("Id_Nome", System.Data.SqlDbType.Int).Value = USU.Id_Nome; CM.Connection = CON; CON.Open(); int qtd = CM.ExecuteNonQuery(); return(qtd); } catch (Exception ex) { throw ex; } }
public List <DTO.Usuario> ConsultarUsuario() { try { SqlConnection sqlCon = new SqlConnection(); sqlCon.ConnectionString = Properties.Settings.Default.CST; SqlCommand CM = new SqlCommand(); CM.CommandType = System.Data.CommandType.Text; CM.CommandText = "SELECT * FROM Usuario"; CM.Connection = sqlCon; SqlDataReader DR; List <DTO.Usuario> listUsuarioDTO = new List <DTO.Usuario>(); sqlCon.Open(); DR = CM.ExecuteReader(); if (DR.HasRows) { while (DR.Read()) { DTO.Usuario usu = new DTO.Usuario(); usu.Id_Nome = Convert.ToInt32(DR["Id_Nome"]); usu.Nome = Convert.ToString(DR["Nome"]); usu.Email = Convert.ToString(DR["Email"]); usu.Login = Convert.ToString(DR["Login"]); usu.Senha = Convert.ToString(DR["Senha"]); usu.Id_Perfil = Convert.ToInt32(DR["Id_Perfil"]); listUsuarioDTO.Add(usu); } } return(listUsuarioDTO); } catch (Exception ex) { throw ex; } }
public ValuesModule() { Get["/Values", true] = async(_, a) => { Task <IEnumerable <DTO.Usuario> > usuarios = BusinessLogicalLayer.BusinessLogicalLayer.UsuarioBusiness.GetAll(); usuarios.Wait(); return(Response.AsJson(usuarios)); }; Post["/values"] = _ => { var jsonString = this.Request.Body.AsString(); var user = new DTO.Usuario() { Nome = "teste", Email = "teste", Senha = "1234", Ativo = true }; UsuarioBusiness.Insert(user); return(Response.AsJson(jsonString)); }; }
public ActionResult Usuario(Guid?id, Guid?obj) { using (var srv = BLL.Factory.GetSecurityService(CurrentUser)) { DTO.Usuario dto = null; if (obj.HasValue) { var result = Models.Site.Session.Pop <YerbaSoft.DTO.Result <DTO.Usuario> >(this.Session, obj.Value); if (result != null) // ésto ocurre cuando apretan F5 ya que la variables PushPop no está más en memoria { dto = result.Data; ViewBag.MsgErr = result.Messages.ToString(new YerbaSoft.DTO.Exceptions.ExceptionConvertTemplateOnlyMessage()); } } if (dto == null) { dto = base.GetFromRequest <DTO.Usuario>(srv); } return(View(dto)); } }
public int InsereUsuario(DTO.Usuario USU) { try { SqlConnection sqlCon = new SqlConnection(); sqlCon.ConnectionString = Properties.Settings.Default.CST; SqlCommand CM = new SqlCommand(); CM.CommandType = System.Data.CommandType.Text; CM.CommandText = "INSERT INTO Usuario (Nome, Email, Login, Senha, Id_Perfil) VALUES (@Nome, @Email, @Login, @Senha, @Id_Perfil);"; CM.Parameters.Add("Nome", System.Data.SqlDbType.VarChar).Value = USU.Nome; CM.Parameters.Add("Email", System.Data.SqlDbType.VarChar).Value = USU.Email; CM.Parameters.Add("Login", System.Data.SqlDbType.VarChar).Value = USU.Login; CM.Parameters.Add("Senha", System.Data.SqlDbType.VarChar).Value = USU.Senha; CM.Parameters.Add("Id_Perfil", System.Data.SqlDbType.Int).Value = USU.Id_Perfil; CM.Connection = sqlCon; sqlCon.Open(); int qtd = CM.ExecuteNonQuery(); return(qtd); } catch (Exception ex) { throw ex; } }
public int EditarUsuario(DTO.Usuario USU) { try { SqlConnection sqlCon = new SqlConnection(); sqlCon.ConnectionString = Properties.Settings.Default.CST; SqlCommand CM = new SqlCommand(); CM.CommandType = System.Data.CommandType.Text; CM.CommandText = "UPDATE Usuario SET Nome=@Nome, Email=@Email, Login=@Login, Senha=@Senha, Id_Perfil=@Id_Perfil WHERE Id_Nome=@Id_Nome;"; CM.Parameters.Add("Id_Nome", System.Data.SqlDbType.Int).Value = USU.Id_Nome; CM.Parameters.Add("Nome", System.Data.SqlDbType.VarChar).Value = USU.Nome; CM.Parameters.Add("Email", System.Data.SqlDbType.VarChar).Value = USU.Email; CM.Parameters.Add("Login", System.Data.SqlDbType.VarChar).Value = USU.Login; CM.Parameters.Add("Senha", System.Data.SqlDbType.VarChar).Value = USU.Senha; CM.Parameters.Add("Id_Perfil", System.Data.SqlDbType.Int).Value = USU.Id_Perfil; CM.Connection = sqlCon; sqlCon.Open(); return(CM.ExecuteNonQuery()); } catch (Exception ex) { throw ex; } }
public static DTO.BLLServices.IClueService GetClueService(DTO.Usuario currentUser) { return(new Service.ClueService(currentUser)); }
public static DTO.BLLServices.IGamesService GetGamesService(DTO.Usuario currentUser) { return(new Service.GamesService(currentUser)); }
public static DTO.BLLServices.ISecurityService GetSecurityService(DTO.Usuario currentUser) { return(new Service.SecurityService(currentUser)); }
public Service(DTO.Usuario currentUser) { this.Session = new DAL.Session($"{Factory.FilesPath}YerbaSoft.Web.Games.Config.xml", $"{Factory.FilesPath}YerbaSoft.Web.Games.Chat.xml"); this.CurrentUser = currentUser; }
public async Task <IHttpActionResult> SaveUsuario(DTO.Usuario usuario) { try { int usuarioId = int.Parse(DbContextAIVH.GetUserName(User)); if (usuario.UsuarioId != 0) { var usuarioDb = db.Usuario.Where(a => a.UsuarioId == usuario.UsuarioId).FirstOrDefault(); usuarioDb.Nombre = usuario.Nombre; usuarioDb.Paterno = usuario.Paterno; usuarioDb.Materno = usuario.Materno; usuarioDb.UsuarioRolId = usuario.RolId; usuarioDb.Fecha = DateTime.Now; usuarioDb.Hora = DateTime.Now.TimeOfDay; usuarioDb.UsuarioIdGenero = usuarioId; usuarioDb.EstatusId = usuario.EstatusId; } else { db.Usuario.Add(new Usuario { Nombre = usuario.Nombre, Paterno = usuario.Paterno, Materno = usuario.Materno, UsuarioRolId = usuario.RolId, Fecha = DateTime.Now, Hora = DateTime.Now.TimeOfDay, UsuarioIdGenero = usuarioId, EstatusId = usuario.EstatusId }); } db.SaveChanges(); AccountController accountController = new AccountController(); IHttpActionResult result = null; if (usuario.UsuarioId != 0 && usuario.Password != "") { result = await accountController.UpdateUserAsync(usuario); } else if (usuario.UsuarioId == 0) { usuario.NickName = db.Usuario.Local.FirstOrDefault().UsuarioId.ToString(); result = await accountController.Register(usuario); } if (result is OkNegotiatedContentResult <bool> status || result == null) { return(Ok(new { message = "El usuario se guardó correctamente." })); } else { return(BadRequest("Error al guardar usuario")); } } catch (Exception Ex) { return(BadRequest("Error al guardar usuario")); } }
public SecurityService(DTO.Usuario currentUser) : base(currentUser) { }
/// <summary> /// Establece el usuario activo (logueado) en la session /// </summary> /// <param name="session">session actual</param> /// <param name="user">objeto Usuario</param> internal static void SetUsuarioActivo(HttpSessionStateBase session, DTO.Usuario user) { session[USER_ACTIVE] = user; }
public GamesService(DTO.Usuario currentUser) : base(currentUser) { }