public async Task <IEnumerable <object> > GetRestaurantsAsync()
 {
     return(await Task.Run(() =>
     {
         using (var _session = SessionNHibernate.OpenSession())
         {
             return _session.CreateCriteria <Restaurant>().List <Restaurant>();
         }
     }));
 }
 public async Task <object> GetRestaurantByIdAsync(int id)
 {
     return(await Task.Run(() =>
     {
         using (var _session = SessionNHibernate.OpenSession())
         {
             return _session.QueryOver <Restaurant>().Where(x => x.RestaurantID == id).SingleOrDefault();
         }
     }));
 }
 private static void ExecuteQuery(string query)
 {
     using (ISession sessao = SessionNHibernate.Criar().OpenSession())
     {
         using (var transacao = sessao.BeginTransaction())
         {
             sessao.CreateSQLQuery(query).ExecuteUpdate();
             transacao.Commit();
         }
     }
 }
 public async Task <object> FilterByRaitingAsync(double rating)
 {
     return(await Task.Run(() =>
     {
         using (var _session = SessionNHibernate.OpenSession())
         {
             return _session.QueryOver <Restaurant>()
             .Where(x => x.Scores.Select(s => s.RatingScore).Average() == rating).SingleOrDefaultAsync();
         }
     }));
 }
Example #5
0
 public Ticket ObterPor(int id)
 {
     try
     {
         using (ISession sessao = SessionNHibernate.Criar().OpenSession())
         {
             return(sessao.Query <Ticket>().FirstOrDefault(onde => onde.Id == id));
         }
     }
     catch
     {
         throw;
     }
 }
Example #6
0
        public async Task <object> AddMealAsync(object toInsert)
        {
            return(await Task.Run(async() =>
            {
                var meal = JsonConvert.DeserializeObject <Meal>(toInsert.ToString());

                using (var session = SessionNHibernate.OpenSession())
                    using (var transaction = session.BeginTransaction())
                    {
                        await session.SaveOrUpdateAsync(meal);

                        await transaction.CommitAsync();
                    };

                return meal;
            }));
        }
        public async Task <object> ApplyRatingAsync(object toInsert)
        {
            return(await Task.Run(() =>
            {
                var score = JsonConvert.DeserializeObject <Score>(toInsert.ToString());

                using (var session = SessionNHibernate.OpenSession())
                    using (var transaction = session.BeginTransaction())
                    {
                        session.SaveOrUpdate(score);

                        transaction.Commit();

                        return score;
                    }
            }));
        }
Example #8
0
 public Ticket ObterUltimo()
 {
     try
     {
         using (ISession sessao = SessionNHibernate.Criar().OpenSession())
         {
             return(sessao.Query <Ticket>().AsQueryable()
                    .Where(UltimoTicket.Hoje)
                    .OrderByDescending(ordem => ordem.DataHoraDeEntrada)
                    .FirstOrDefault());
         }
     }
     catch
     {
         throw;
     }
 }
        public async Task <object> CreateRestaurantAsync(object toInsert)
        {
            return(await Task.Run(() =>
            {
                var restaurant = JsonConvert.DeserializeObject <Restaurant>(toInsert.ToString());

                using (var _session = SessionNHibernate.OpenSession())
                    using (var transaction = _session.BeginTransaction())
                    {
                        _session.SaveOrUpdate(restaurant);

                        transaction.Commit();
                    };

                return restaurant;
            }));
        }
Example #10
0
 public void Salvar(Ticket ticket)
 {
     if (ticket.Valido())
     {
         using (ISession sessao = SessionNHibernate.Criar().OpenSession())
         {
             using (ITransaction trasacao = sessao.BeginTransaction())
             {
                 try
                 {
                     sessao.SaveOrUpdate(ticket);
                     sessao.Flush();
                     trasacao.Commit();
                 }
                 catch
                 {
                     trasacao.Rollback();
                     throw;
                 }
             }
         }
     }
 }
Example #11
0
        public async Task <object> CreateOrderAsync(object toInsert)
        {
            return(await Task.Run(() =>
            {
                var order = JsonConvert.DeserializeObject <CustomerOrder>(toInsert.ToString());

                //RootObject customerLocation = await _locationManager.GetLocationAsync(order.Address);

                //RootObject restaurantLocation = await _locationManager.GetLocationAsync(order.Restaurant.Address);

                //Gets latitude and Longitude then set the order object with coordinates
                //_locationManager.CalculateETA(customerLocation, restaurantLocation);

                using (var session = SessionNHibernate.OpenSession())
                    using (var transaction = session.BeginTransaction())
                    {
                        session.SaveOrUpdate(order);

                        transaction.Commit();
                    };

                return order;
            }));
        }