コード例 #1
0
 public async Task <IEnumerable <object> > GetRestaurantsAsync()
 {
     return(await Task.Run(() =>
     {
         using (var _session = SessionNHibernate.OpenSession())
         {
             return _session.CreateCriteria <Restaurant>().List <Restaurant>();
         }
     }));
 }
コード例 #2
0
 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();
         }
     }));
 }
コード例 #3
0
 private static void ExecuteQuery(string query)
 {
     using (ISession sessao = SessionNHibernate.Criar().OpenSession())
     {
         using (var transacao = sessao.BeginTransaction())
         {
             sessao.CreateSQLQuery(query).ExecuteUpdate();
             transacao.Commit();
         }
     }
 }
コード例 #4
0
 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();
         }
     }));
 }
コード例 #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;
     }
 }
コード例 #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;
            }));
        }
コード例 #7
0
        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;
                    }
            }));
        }
コード例 #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;
     }
 }
コード例 #9
0
        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;
            }));
        }
コード例 #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;
                 }
             }
         }
     }
 }
コード例 #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;
            }));
        }