Beispiel #1
0
        // GET: CalendarItems/ClassDescription/2
        // Show description of a class
        public ActionResult ClassDescription(string id)
        {
            int idInt;

            try
            {
                idInt = Int32.Parse(id);
            }
            catch
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CalendarItem gymClass = db.CalendarItems.Find(idInt);

            if (gymClass == null)
            {
                return(HttpNotFound());
            }

            ViewBag.UserId = User.Identity.GetUserId();

            var pics2 = GetPics.Get2Pics(gymClass.GymClass.Name);

            ViewBag.pic0 = pics2[0];
            ViewBag.pic1 = pics2[1];

            TempData["CurrentClass"] = gymClass.Id;
            return(View(gymClass));
        }
Beispiel #2
0
        public ActionResult BookClass(string id, bool AJAX = false)
        {
            var strCurrentUserId = User.Identity.GetUserId();

            int idInt;

            try
            {
                idInt = Int32.Parse(id);
            }
            catch
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            CalendarItem gymClass = db.CalendarItems.Find(idInt);

            if (gymClass == null)
            {
                return(HttpNotFound());
            }

            // get UserIds string and check how many people in class
            List <string> gymClassAttenders = new List <string>();
            int           numInClass        = gymClass.UserIds == "" ? 0 : gymClass.UserIds.Count(x => x == ',') + 1;

            if (numInClass != 0)
            {
                gymClassAttenders = gymClass.UserIds.Split(',').ToList();
            }

            var userInString = gymClassAttenders.Find(x => x == strCurrentUserId);

            if (userInString != null || numInClass >= gymClass.MaxPeople)
            {
                return(RedirectToAction("Index", "CalendarItems"));
            }

            gymClassAttenders.Add(strCurrentUserId);
            gymClass.UserIds = string.Join(",", gymClassAttenders.Select(n => n.ToString()).ToArray());
            db.SaveChanges();

            TempData["CurrentClass"] = gymClass.Id;

            if (AJAX)
            {
                return(null);
            }

            //return Redirect(Url.Action("Index") + "#" + gymClass.Id);

            var pics2 = GetPics.Get2Pics(gymClass.GymClass.Name);

            ViewBag.pic0 = pics2[0];
            ViewBag.pic1 = pics2[1];

            return(View(gymClass)); /// go to page showing confirmation of booking
        }
Beispiel #3
0
        // GET: GymClasses/Show/5
        public ActionResult Show(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //GymClass gymClass = db.GymClasses.Find(id);
            var gymClass = db.GymClasses.SingleOrDefault(d => d.Name == id);

            if (gymClass == null)
            {
                return(HttpNotFound());
            }

            ViewBag.pics = GetPics.Get2Pics(gymClass.Name);

            return(View(gymClass));
        }
Beispiel #4
0
        public ActionResult CancelClass(string id, bool AJAX = false)
        {
            var strCurrentUserId = User.Identity.GetUserId();
            int idInt;

            try
            {
                idInt = Int32.Parse(id);
            }
            catch
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CalendarItem gymClass = db.CalendarItems.Find(idInt);

            if (gymClass == null || gymClass.UserIds == "") // if user enters web address parameters manually and they are not valid
            {
                return(HttpNotFound());
            }
            // get users who have booked this class
            List <string> gymClassAttenders = gymClass.UserIds.Split(',').ToList();

            gymClassAttenders.Remove(strCurrentUserId);
            gymClass.UserIds = string.Join(",", gymClassAttenders.Select(n => n.ToString()).ToArray());
            db.SaveChanges();

            TempData["CurrentClass"] = gymClass.Id;

            if (AJAX)
            {
                return(null);
            }

            //return Redirect(Url.Action("Index") + "#" + gymClass.Id);

            var pics2 = GetPics.Get2Pics(gymClass.GymClass.Name);

            ViewBag.pic0 = pics2[0];
            ViewBag.pic1 = pics2[1];

            return(View(gymClass)); /// go to page showing confirmation of cancelled class
        }