Esempio n. 1
0
 public Driver Login(LoginBody loginBody)
 {
     using (ISession session = NH.OpenSession())
     {
         try
         {
             var _password = session.CreateSQLQuery($"select Drv_Password from dbo.Drivers where Drv_Ident={loginBody.ident}").UniqueResult <string>();
             Log(_password);
             var check = loginBody.password == _password;//BCrypt.Net.BCrypt.CheckPassword(loginBody.password, _password);
             if (check)
             {
                 return(session.Query <Driver>().FetchMany(x => x.OpinionList)
                        .Where(x => x.Drv_Identity == loginBody.ident).FirstOrDefault());
             }
             else
             {
                 return(null);
             }
             //   return result;//result.FirstOrDefault();
         }
         catch (Exception e)
         {
             Log(e.Message);
             return(null);
         }
     }
 }
Esempio n. 2
0
 public List <Driver> GetActiveDrivers()
 {
     using (var session = NH.OpenSession())
     {
         return(session.Query <Driver>().Where(x => x.Drv_Timing >= DateTime.Now.AddMinutes(-30)).ToList());
     }
 }
Esempio n. 3
0
        public bool Register(RegisterBody registerBody)
        {
            using (var session = NH.OpenSession())
            {
                if (session.Query <Driver>().Where(x => x.Drv_Identity == registerBody.driver.Drv_Identity).FirstOrDefault() != null)
                {
                    return(false);
                }
                else
                {
                    try
                    {
                        using (var trans = session.BeginTransaction())
                        {
                            var driv = registerBody.driver;
                            session.CreateSQLQuery($"insert into dbo.drivers(Drv_Name,Drv_Surname,Drv_Identity,Drv_Password,Drv_Phone) values ('{driv.Drv_Name}','{driv.Drv_Surname}','{driv.Drv_Identity}','','{driv.Drv_Phone}')").ExecuteUpdate();
                            trans.Commit();
                        }

                        session.CreateSQLQuery($"update dbo.drivers set Drv_Password='******'").ExecuteUpdate();
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Log(e.Message);
                        return(false);
                    }
                }
            }
        }
Esempio n. 4
0
 public bool Locate(LocateBody locateBody)//string ident, decimal lat, decimal lng)
 {
     try
     {
         using (var session = NH.OpenSession())
         {
             session.CreateSQLQuery($"update dbo.drivers set Drv_Latitude={locateBody.lat},Drv_Longitude={locateBody.lng},Drv_Timing={DateTime.Now} where Drv_Ident={locateBody.ident}").ExecuteUpdate();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 5
0
 public bool AddOpinion(Opinion opinion)
 {
     using (ISession session = NH.OpenSession())
     {
         try
         {
             using (var transaction = session.BeginTransaction())
             {
                 session.Save(opinion);
                 transaction.Commit();
             }
             return(true);//result.FirstOrDefault();
         }
         catch
         {
             return(false);
         }
     }
 }