public void ConfirmReservTables(int restId, int schemaId, List <int> tablesIds, DateTime date, ApplicationUser user, string name, string phone)
        {
            using (GoodTasteContext context = new GoodTasteContext())
            {
                ApplicationUser u = null;
                if (user != null)
                {
                    u = context.Users.Find(user.Id);
                }

                foreach (var tableId in tablesIds)
                {
                    Table            table  = context.Tables.Find(tableId);
                    TableReservation reserv = new TableReservation();
                    reserv.Table = table;
                    reserv.User  = u;
                    reserv.ReservedAndConfirmed      = true;
                    reserv.ConfirmedByAdministration = true;
                    reserv.Reserved         = false;
                    reserv.Date             = date;
                    reserv.ContactInfoName  = name.Trim();
                    reserv.ContactInfoPhone = phone.Trim();
                    context.TableReservations.Add(reserv);
                }
                context.SaveChanges();
            }
        }
        public EventSearchViewModel GetListEventSearch()
        {
            using (GoodTasteContext context = new GoodTasteContext())
            {
                try
                {
                    List <RestaurantEvent> EventList = context.RestaurantEvent.Include(t => t.Restaurant)
                                                       .Include(t => t.EventTypes).ToList();
                    List <EventType> EventTypes = context.EventTypes.Include(t => t.RestaurantEvents).OrderBy(t => t.Name).ToList();
                    List <SearchCategory <EventType> > EventTypesInfo = new List <SearchCategory <EventType> >();

                    for (int i = 0; i < EventTypes.Count; i++)
                    {
                        EventTypesInfo.Add(new SearchCategory <EventType>()
                        {
                            Category = EventTypes[i], IsSelected = false, Count = GetEventCountByType(EventTypes[i].Id)
                        });
                    }
                    EventSearchViewModel result = new Models.EventSearchViewModel();
                    result.Events = EventList;
                    result.Types  = EventTypesInfo;
                    result.IsSelectedAnyCategory = false;
                    return(result);
                }
                catch
                {
                    throw new Exception("Events not found");
                }
            }
        }
        public double GetRestaurantRank(int?restId)
        {
            using (GoodTasteContext context = new GoodTasteContext())
            {
                List <RestaurantReview> reviews = (from x in context.RestaurantReviews
                                                   where x.Restaurant.Id == restId
                                                   select x).ToList();
                double rank  = 0;
                int    count = 0;
                for (int i = 0; i < reviews.Count; i++)
                {
                    rank += reviews[i].Rank;
                    if (reviews[i].Rank > 0)
                    {
                        count++;
                    }
                }
                if (count == 0)
                {
                    return(0);
                }

                return(Math.Round(rank / count, 1));
            }
        }
Ejemplo n.º 4
0
 public ApplicationUser GetUser(string id)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         return((from x in context.Users where x.Id == id select x).FirstOrDefault());
     }
 }
Ejemplo n.º 5
0
 public void SignUp(ApplicationUser user)
 {
     try
     {
         string message;
         using (GoodTasteContext context = new GoodTasteContext())
         {
             if (IsUserExist(context, user))
             {
                 message = "Such user is already exist!";
                 throw new Exception(message);
             }
             if (!IsInputDataCorrect(user))
             {
                 message = "User data isn't correct!";
                 throw new Exception(message);
             }
             else
             {
                 context.Users.Add(user);
                 context.SaveChanges();
             }
         }
     }
     catch (Exception)
     {
     }
 }
        public List <int> GetRestaurantsIDByCuisines(List <int> idEl)
        {
            using (GoodTasteContext context = new GoodTasteContext())
            {
                try
                {
                    List <int> id   = new List <int>();
                    var        rest = context.Cuisines.Include(t => t.Restaurants)
                                      .Where(x => idEl.Contains(x.Id)).Select(t => t.Restaurants).ToList();

                    for (int i = 0; i < rest.Count(); i++)
                    {
                        List <int> temp = new List <int>();
                        for (int j = 0; j < rest[i].ToList().Count(); j++)
                        {
                            temp.Add(rest[i].ToList()[j].Id);
                        }
                        if (id.Count > 0)
                        {
                            id = id.Intersect(temp).ToList();
                        }
                        else
                        {
                            id = temp;
                        }
                    }

                    return(id);
                }
                catch
                {
                    throw new Exception("Restaurants not found");
                }
            }
        }
Ejemplo n.º 7
0
 public ApplicationUser LogIn(string email, string password)
 {
     try
     {
         string message;
         using (GoodTasteContext context = new GoodTasteContext())
         {
             if (!IsUserExist(context, email, password))
             {
                 message = "Your email or password isn't correct!";
                 throw new Exception(message);
             }
             else
             {
                 var user = context.Users.Where(u => u.Email == email)
                            .SingleOrDefault();
                 return(user);
             }
         }
     }
     catch (Exception)
     {
         throw new Exception();
     }
 }
 public Restaurant GetRestaurant(int?id)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             Restaurant result = context.Restaurants.Include(r => r.City).Include(r => r.Cuisines).
                                 Include(r => r.Likes).Include(r => r.Map).Include(r => r.Menu).
                                 Include(r => r.RestaurantEvent).Include(r => r.RestaurantFeatures).Include(r => r.RestaurantGroup).
                                 Include(r => r.RestaurantSchemas).Include(r => r.Reviews).Include(r => r.SpecialWorkHours).
                                 Include(r => r.WorkHours).Where(r => r.Id == id).FirstOrDefault();
             result.City              = context.Cities.Where(t => t.Id == result.City.Id).FirstOrDefault();
             result.City.Country      = context.Countries.Where(t => t.Id == result.City.Country.Id).FirstOrDefault();
             result.Reviews           = context.RestaurantReviews.Include(t => t.User).ToList();
             result.RestaurantEvent   = context.RestaurantEvent.Include(t => t.EventTypes).ToList();
             result.Menu              = context.Menus.Include(t => t.MealGroups.Select(m => m.Meals.Select(c => c.Currency))).ToList();
             result.RestaurantSchemas = context.RestaurantSchemas.Include(t => t.Tables.Select(r => r.TableReservation.Select(u => u.User))).ToList();
             result.Map = context.Maps.Where(x => x.id == result.Map.id).SingleOrDefault();
             return(result);
         }
         catch (Exception ex)
         {
             throw new Exception("");
         }
     }
 }
 public void RemoveReserv(int?reservId)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         context.TableReservations.Remove(context.TableReservations.Find(reservId));
         context.SaveChanges();
     }
 }
 public int GetEventCountByType(int id)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         var temp = context.RestaurantEvent.Include(t => t.EventTypes).Where(e => e.EventTypes.Select(x => x.Id).ToList().Contains(id)).ToList();
         return(temp.Count >= 0 ? temp.Count : 0);
     }
 }
Ejemplo n.º 11
0
        public List <RestaurantEvent> SearchEvents(string searchText, string CheckEl)
        {
            using (GoodTasteContext context = new GoodTasteContext())
            {
                try
                {
                    List <RestaurantEvent> result;
                    if (CheckEl != null)
                    {
                        string[]   el   = CheckEl.Split(',');
                        List <int> idEl = new List <int>();
                        for (int i = 0; i < el.Count(); i++)
                        {
                            idEl.Add(int.Parse(el[i].Trim()));
                        }

                        var re = GetEventTypes(idEl).Select(t => t.RestaurantEvents).ToList();

                        List <int> id = new List <int>();
                        for (int i = 0; i < re.Count(); i++)
                        {
                            for (int j = 0; j < re[i].ToList().Count(); j++)
                            {
                                id.Add(re[i].ToList()[j].Id);
                            }
                        }
                        id = id.Distinct().ToList();
                        if (searchText == null)
                        {
                            result = context.RestaurantEvent.Include(t => t.Restaurant)
                                     .Include(t => t.EventTypes).Where(t => id.Contains(t.Id)).ToList();
                        }
                        else
                        {
                            result = context.RestaurantEvent.Include(t => t.Restaurant)
                                     .Include(t => t.EventTypes).Where(t => id.Contains(t.Id))
                                     .Where(t => t.Name.Contains(searchText)).ToList();
                        }
                    }
                    else if (searchText.Length > 0)
                    {
                        result = context.RestaurantEvent.Include(t => t.Restaurant)
                                 .Include(t => t.EventTypes).Where(t => t.Name.Contains(searchText)).ToList();
                    }
                    else
                    {
                        result = context.RestaurantEvent.Include(t => t.Restaurant)
                                 .Include(t => t.EventTypes).ToList();
                    }

                    return(result);
                }
                catch
                {
                    throw new Exception("Events not found");
                }
            }
        }
        private List <RestaurantEvent> GetEventsByDate(DateTime from, DateTime to, GoodTasteContext context)
        {
            List <RestaurantEvent> EventList = context.RestaurantEvent.Include(t => t.Restaurant)
                                               .Include(t => t.EventTypes)
                                               .Where(t => t.StartDate >= from && t.StartDate <= to)
                                               .ToList();

            return(EventList);
        }
        private List <RestaurantEvent> GetEventsByName(string searchText, GoodTasteContext context)
        {
            List <RestaurantEvent> EventList = context.RestaurantEvent.Include(t => t.Restaurant)
                                               .Include(t => t.EventTypes)
                                               .Where(t => t.Name.Contains(searchText))
                                               .ToList();

            return(EventList);
        }
Ejemplo n.º 14
0
 public string GetCurrectUserId()
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         //ApplicationUser currentUser = context.Users.FirstOrDefault(x => x.Id == HttpContext.Current.User.Identity.GetUserId());
         ApplicationUser user = context.Users.FirstOrDefault();
         return(user.Id);
     }
 }
Ejemplo n.º 15
0
        public JsonResult GetSearchData(string term)
        {
            List <string> restaurantNames;

            using (GoodTasteContext context = new GoodTasteContext())
            {
                restaurantNames = context.Restaurants.Where(r => r.Name.Contains(term)).Select(r => r.Name).ToList();
            }
            return(Json(restaurantNames, JsonRequestBehavior.AllowGet));
        }
 public void RemoveReserv(List <TableReservation> reservs)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         foreach (var item in reservs)
         {
             TableReservation remove = context.TableReservations.Find(item.Id);
             context.TableReservations.Remove(remove);
         }
         context.SaveChanges();
     }
 }
        public List <EventType> GetEventTypes(List <int> idEl)
        {
            using (GoodTasteContext context = new GoodTasteContext())
            {
                List <EventType> EventTypes = new List <EventType>();

                EventTypes = context.EventTypes.Include(t => t.RestaurantEvents)
                             .Where(x => idEl.Contains(x.Id)).OrderBy(x => x.Name).ToList();

                return(EventTypes);
            }
        }
Ejemplo n.º 18
0
        private bool IsUserExist(GoodTasteContext context, ApplicationUser currentUser)
        {
            var usersQuery = context.Users;

            foreach (var user in usersQuery)
            {
                if (user.Email == currentUser.Email)
                {
                    return(true);
                }
            }
            return(false);
        }
 public void ConfirmReservByAdministration(int reservId)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         var reserv = context.TableReservations.Find(reservId);
         if (reserv == null)
         {
             throw new ArgumentNullException();
         }
         reserv.ConfirmedByAdministration = true;
         reserv.ReservedAndConfirmed      = true;
         reserv.Reserved = false;
         context.SaveChanges();
     }
 }
 public List <int> GetRestaurantsIDByName(string name)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             List <int> result = context.Restaurants.Where(r => r.Name.Contains(name)).Select(t => t.Id).ToList();
             return(result);
         }
         catch
         {
             throw new Exception("Restaurants not found");
         }
     }
 }
 public List <Cuisine> GetAllCuisines()
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             List <Cuisine> result = context.Cuisines.OrderBy(x => x.Name).ToList();
             return(result);
         }
         catch
         {
             throw new Exception("Cuisines not found");
         }
     }
 }
 public List <Neighborhood> GetAllNeighborhoods()
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             List <Neighborhood> result = context.Neighborhoods.Where(n => n.City.Id == 1).OrderBy(x => x.Name).ToList();
             return(result);
         }
         catch
         {
             throw new Exception("Neighborhood features not found");
         }
     }
 }
 public List <MealGroup> GetAllMealGroups()
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             List <MealGroup> result = context.MealGroups.OrderBy(x => x.Name).ToList();
             return(result);
         }
         catch
         {
             throw new Exception("Restaurant features not found");
         }
     }
 }
 public OrderFood GetOrderFood(int Id, int value)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             OrderFood OF = new Models.OrderFood();
             return(OF);
         }
         catch
         {
             throw new Exception("Order food not found");
         }
     }
 }
 public List <Table> GetListTables(List <int> ids)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             List <Table> Tables = context.Tables.Where(t => ids.Contains(t.Id)).ToList();
             return(Tables);
         }
         catch
         {
             throw new Exception("Tables not found");
         }
     }
 }
Ejemplo n.º 26
0
        private bool IsUserExist(GoodTasteContext context,
                                 string email, string password)
        {
            var usersQuery = context.Users;

            foreach (var user in usersQuery)
            {
                if (user.Email == email &&
                    user.PasswordHash == password)
                {
                    return(true);
                }
            }
            return(false);
        }
 public Menu GetRestMenu(int id)
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             Menu menu = context.Menus.Include(t => t.MealGroups.Select(m => m.Meals.Select(c => c.Currency))).Where(t => t.Restaurant.Id == id).FirstOrDefault();
             return(menu);
         }
         catch
         {
             throw new Exception("Menu not found");
         }
     }
 }
Ejemplo n.º 28
0
 public ApplicationUser GetUserById(string id)
 {
     try
     {
         using (GoodTasteContext context = new GoodTasteContext())
         {
             ApplicationUser user = context.Users.Where(d => d.Id == id).SingleOrDefault();
             return(user);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public RestaurantShemaViewModel GetRestaurantViewModelSchema(int?id)
        {
            using (GoodTasteContext context = new GoodTasteContext())
            {
                try
                {
                    Restaurant       Rest   = context.Restaurants.Find(id);
                    RestaurantSchema Schema = Rest.RestaurantSchemas.FirstOrDefault();
                    Schema = context.RestaurantSchemas.Include(t => t.Restaurant).FirstOrDefault(t => t.Id == id);
                    Schema = context.RestaurantSchemas.Include(t => t.Tables).FirstOrDefault();
                    RestaurantShemaViewModel vmSchema = new RestaurantShemaViewModel();
                    vmSchema.Id           = Schema.Id;
                    vmSchema.Name         = Schema.Name;
                    vmSchema.RestaurantId = Convert.ToInt32(id);
                    List <TableViewModel> vmTables = new List <TableViewModel>();

                    foreach (var table in Schema.Tables)
                    {
                        TableViewModel vmTable = new TableViewModel {
                            Id = table.Id, X = table.X, Y = table.Y, Seats = table.Seats, ReservedAndConfirmed = false, Reserved = false
                        };
                        foreach (var reserv in table.TableReservation)
                        {
                            if (reserv.Date.Date == DateTime.Now.Date && reserv.ReservedAndConfirmed == true)
                            {
                                vmTable.ReservedAndConfirmed = true;
                                break;
                            }
                            else if (reserv.Date.Date == DateTime.Now.Date && reserv.Reserved == true)
                            {
                                vmTable.Reserved = true;
                                break;
                            }
                        }
                        vmTables.Add(vmTable);
                    }

                    vmSchema.Tables  = vmTables;
                    vmSchema.XLength = Schema.XLength;
                    vmSchema.YLength = Schema.YLength;
                    return(vmSchema);
                }
                catch
                {
                    throw new Exception("Restaurant not found");
                }
            }
        }
 public List <RestaurantEvent> GetListRestaurantEvents()
 {
     using (GoodTasteContext context = new GoodTasteContext())
     {
         try
         {
             List <RestaurantEvent> result = context.RestaurantEvent.Include(t => t.Restaurant)
                                             .Include(t => t.EventTypes).ToList();
             return(result);
         }
         catch
         {
             throw new Exception("Events not found");
         }
     }
 }