Esempio n. 1
0
        public IEnumerable <dynamic> GetMonthlySales()
        {
            using (var ctx = new HamerimDbContext())
            {
                var data = ctx.Orders.GroupBy(order => order.Date.Month).AsEnumerable().Select(group => new
                {
                    Month          = group.Key,
                    AmountOfOrders = group.Count(),
                    Profit         = group.Sum(order => order.TotalCost())
                }).ToList();

                for (int month = 1; month <= 12; month++)
                {
                    if (!data.Any(entry => entry.Month == month))
                    {
                        data.Add(new
                        {
                            Month          = month,
                            AmountOfOrders = 0,
                            Profit         = 0
                        });
                    }
                }

                return(data);
            }
        }
Esempio n. 2
0
        public ActionResult FilterClubs(int maxPriceFilter = Int32.MaxValue, string nameFilter = "", string cityFilter = "")
        {
            using (var ctx = new HamerimDbContext())
            {
                IEnumerable <Club> filteredClubs = ctx.Clubs.Include(cl => cl.Address).ToList();;

                if (!nameFilter.IsEmpty())
                {
                    filteredClubs = filteredClubs.Where(club => club.Name.Contains(nameFilter));
                }

                if (!cityFilter.IsEmpty())
                {
                    filteredClubs = filteredClubs.Where(club => club.Address.City == cityFilter);
                }

                filteredClubs = filteredClubs.Where(club => club.Cost <= maxPriceFilter);

                // Creating new anonymus type to avoid circular reference in JSON
                var data = filteredClubs.Select(club => new
                {
                    club.Id,
                    club.Name,
                    club.Cost,
                    Address = new
                    {
                        club.Address.City,
                        club.Address.Street,
                        club.Address.HouseNumber
                    }
                });

                return(Json(data, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 3
0
 public bool ValidateUser(string username, string password)
 {
     using (var ctx = new HamerimDbContext())
     {
         return(ctx.Users.Any(user => user.Username == username &&
                              user.Password == password));
     }
 }
Esempio n. 4
0
        // GET: Order
        public ActionResult NewOrder()
        {
            using (var ctx = new HamerimDbContext())
            {
                ViewBag.Clubs  = ctx.Clubs.Include(cl => cl.Address).ToList();
                ViewBag.Cities = ctx.ClubAddresses.Select(address => address.City).Distinct().ToList();
            }

            return(View());
        }
Esempio n. 5
0
        public ActionResult DeleteOrder(int id)
        {
            using (var ctx = new HamerimDbContext())
            {
                ctx.Orders.Remove(ctx.Orders.Find(id));
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 6
0
        public ActionResult EditCategory(int id, string title)
        {
            using (var ctx = new HamerimDbContext())
            {
                ctx.ServiceCategories.Find(id).Title = title;
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 7
0
        // GET: Admin
        public ActionResult Index()
        {
            using (var ctx = new HamerimDbContext())
            {
                ViewBag.Clubs      = ctx.Clubs.Include(club => club.Address).ToList();
                ViewBag.Services   = ctx.Services.Include(service => service.Category).ToList();
                ViewBag.Categories = ctx.ServiceCategories.ToList();
                ViewBag.Orders     = ctx.Orders.Include(order => order.Club).ToList();
            }

            return(View());
        }
Esempio n. 8
0
        public ActionResult EditService(int id, string title, int cost, int category)
        {
            using (var ctx = new HamerimDbContext())
            {
                Service service = ctx.Services.Find(id);
                service.Title    = title;
                service.Cost     = cost;
                service.Category = ctx.ServiceCategories.Find(category);
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 9
0
        public ActionResult ViewOrder(int orderNumber)
        {
            using (var ctx = new HamerimDbContext())
            {
                if (ctx.Orders.Any(order => order.Id == orderNumber))
                {
                    return(RedirectToAction("FinishedOrder", new { orderNumber }));
                }

                ViewBag.ErrorMessage = "לא נמצאה הזמנה בעלת מספר הזיהוי שצויין";
                return(View());
            }
        }
Esempio n. 10
0
        public ActionResult AddCategory(string title)
        {
            using (var ctx = new HamerimDbContext())
            {
                ctx.ServiceCategories.Add(new ServiceCategory()
                {
                    Title = title
                });

                ctx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 11
0
        public ActionResult AfterChooseClub(int Id)
        {
            using (var ctx = new HamerimDbContext())
            {
                var chosenClub = ctx.Clubs.Include(cl => cl.Address).First(club => club.Id == Id);
                ViewBag.ChosenClub       = chosenClub;
                ViewBag.UnavailableDates = chosenClub.ClubOrders.Where(club => club.Date >= DateTime.Today)
                                           .Select(order => order.Date).ToList();
                ViewBag.ServiceCategories =
                    ctx.ServiceCategories.Include(category => category.ServicesInCategory).ToList();
            }

            return(View());
        }
Esempio n. 12
0
        public ActionResult FinishedOrder(int orderNumber)
        {
            using (var ctx = new HamerimDbContext())
            {
                ViewBag.Order = ctx.Orders
                                .Include(order => order.Club)
                                .Include(order => order.Club.Address)
                                .Include(order => order.ServicesInOrder)
                                .Include(order => order.ServicesInOrder.Select(service => service.Category))
                                .FirstOrDefault(order => order.Id == orderNumber);
            }

            return(View());
        }
Esempio n. 13
0
        public IEnumerable <int> GetMostPopularServices(int month)
        {
            using (var ctx = new HamerimDbContext())
            {
                var groupedServices =
                    ctx.Orders.Where(order => order.Date.Month == month)
                    .SelectMany(order => order.ServicesInOrder)
                    .GroupBy(service => service.Id);

                return(groupedServices.Where(group => group.Count() ==
                                             groupedServices.Max(groupsToCount => groupsToCount.Count()))
                       .Select(group => ctx.Services.FirstOrDefault(service => service.Id == group.Key).Id)
                       .ToList());
            }
        }
Esempio n. 14
0
        public ActionResult AddService(string title, int cost, int category)
        {
            using (var ctx = new HamerimDbContext())
            {
                ctx.Services.Add(new Service()
                {
                    Title    = title,
                    Cost     = cost,
                    Category = ctx.ServiceCategories.Find(category)
                });
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 15
0
        public ActionResult EditClub(int id, string name, int cost, string city, string street, int houseNumber = 0)
        {
            using (var ctx = new HamerimDbContext())
            {
                Club club = ctx.Clubs.Find(id);
                club.Name                = name;
                club.Cost                = cost;
                club.Address.City        = city;
                club.Address.Street      = street;
                club.Address.HouseNumber = houseNumber;
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 16
0
        public ActionResult BookOrder(int clubId, string clientName, string clientPhone, string txtDateTime, List <int> serviceIds)
        {
            using (HamerimDbContext ctx = new HamerimDbContext())
            {
                Order newOrder = new Order
                {
                    Date            = DateTime.ParseExact(txtDateTime, "MM/dd/yyyy", null),
                    Club            = ctx.Clubs.Find(clubId),
                    ClientName      = clientName,
                    ClientPhone     = clientPhone,
                    ServicesInOrder = serviceIds != null?serviceIds.Select(id => ctx.Services.Find(id)).ToList() : null
                };

                ctx.Orders.Add(newOrder);
                ctx.SaveChanges();

                return(RedirectToAction("FinishedOrder", new { orderNumber = newOrder.Id }));
            }
        }
Esempio n. 17
0
        public ActionResult AddClub(string name, int cost, string city, string street, int houseNumber = 0)
        {
            using (var ctx = new HamerimDbContext())
            {
                ctx.Clubs.Add(new Club()
                {
                    Name    = name,
                    Cost    = cost,
                    Address = new ClubAddress()
                    {
                        City        = city,
                        Street      = street,
                        HouseNumber = houseNumber
                    }
                });
                ctx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 18
0
        public async Task <ActionResult> GetLocations()
        {
            using (var ctx = new HamerimDbContext())
            {
                List <dynamic> locations = new List <dynamic>();
                dynamic[]      results;

                var tasks = ctx.Clubs.ToList().Select(GetClubLocation);
                results = await Task.WhenAll(tasks);

                locations.AddRange(results
                                   .Select(result => new
                {
                    lat = JArray.Parse(result.Data)[0].Value <string>("lat"),
                    lon = JArray.Parse(result.Data)[0].Value <string>("lon"),
                    result.Club
                }));

                return(Json(locations, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 19
0
        public IEnumerable <dynamic> OrdersByClub()
        {
            using (var ctx = new HamerimDbContext())
            {
                var clubs = ctx.Clubs.ToList();

                var data = ctx.Orders.GroupBy(order => order.Club).AsEnumerable().Select(group => new
                {
                    Club           = group.Key.Name,
                    AmountOfOrders = group.Count()
                }).ToList();

                clubs = clubs.Where(club => !data.Any(entry => entry.Club == club.Name)).ToList();

                data.AddRange(clubs.Select(club => new
                {
                    Club           = club.Name,
                    AmountOfOrders = 0
                }).ToList());

                return(data);
            }
        }
Esempio n. 20
0
        public ActionResult Index(string username, string password)
        {
            if (permissionsService.ValidateUser(username, password))
            {
                User connectedUser;

                using (var ctx = new HamerimDbContext())
                {
                    connectedUser = ctx.Users.First(user => user.Username == username &&
                                                    user.Password == password);
                    Session["User"] = connectedUser;
                }

                return(connectedUser.IsAdmin ?
                       RedirectToAction("Index", "Admin") :
                       RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.ErrorMessage = "פרטי ההתחברות אינם נכונים";
                return(View());
            }
        }