Beispiel #1
0
        public ResponseHelper Acceder(LoginViewModel model, bool includes)
        {
            var rm = new ResponseHelper();

            try
            {
                using (var ctx = _dbContextScopeFactory.Create())
                {
                    //string rol = "";
                    model.Password = ExtensionsHelpers.Hash(model.Password);
                    var usuario = _usuariosRepository.SingleOrDefault(x => x.Email.Equals(model.username) && x.Password.Equals(model.Password), x => x.Rol);


                    if (includes)
                    {
                        if (usuario != null)
                        {
                            UserSessionHelper.AddUserToSession(usuario.Id.ToString());
                            UserSessionHelper.AddTipeUser(
                                ExtensionsHelpers.Hash(usuario.Rol.Rol[0].ToString().ToUpper()));

                            rm.SetResponse(true);
                            rm.Result = usuario.Nombres;
                        }
                        else
                        {
                            rm.SetResponse(false, "Correo o contraseña incorrecta");
                        }
                    }
                    else
                    {
                        if (usuario != null)
                        {
                            rm.SetResponse(true);
                            rm.Result = usuario.Nombres;
                        }
                        else
                        {
                            rm.SetResponse(false, "Correo o contraseña incorrecta");
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }


            return(rm);
        }