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();
         }
     }));
 }
 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 #4
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;
                    }
            }));
        }
        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 #7
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;
            }));
        }