// POST: /NewSpaceRequest/Delete/5
        //[HttpPost, ActionName("Review")]
        //[ValidateAntiForgeryToken]
        public ActionResult Approve(int id)
        {
            if (ViewBag.UserRole != GlobalRole.REGULAR)
            {
                NewSpaceRequest newspacerequest = (NewSpaceRequest)db.NewSpaceRequests.Find(id);
                Space space = new Space();
                space.capacity = newspacerequest.capacity;
                space.increase = newspacerequest.increase;
                space.key = newspacerequest.SpaceID;
                space.Name = newspacerequest.name;
                space.PI = (ApplicationUser)db.Users.Find(newspacerequest.requester_key);
                space.PIKey = newspacerequest.requester_key;

                //make our progress bars look pretty
                Random random = new Random();
                space.used = random.Next(0, space.capacity);

                UserSpace userspace = new UserSpace();
                userspace.space = space;
                userspace.user = (ApplicationUser)db.Users.Find(newspacerequest.requester_key);
                userspace.userKey = newspacerequest.requester_key;

                userspace.role = SpaceRole.DATAMANAGER;

                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ProjectContext()));
                ApplicationUser currentUser = manager.FindById(User.Identity.GetUserId());
                if (currentUser.role != GlobalRole.REGULAR)
                {

                    db.Spaces.Add(space);
                    db.UserSpaces.Add(userspace);
                    db.NewSpaceRequests.Remove(newspacerequest);
                    db.SaveChanges();

                    ///////////////////////////////
                    ///////////////////////////////
                    ////Send Email to Requester////
                    ///////////////////////////////
                    ///////////////////////////////

                }

            }

            return RedirectToAction("../Dashboard");
        }
        // GET: /UserSpace/Create/5
        public ActionResult Create(int? id)
        {
            if(id == null)
            {
                return Redirect("../Dashboard");
            }
            Space space = db.Spaces.Find(id);
            List<ApplicationUser> alreadyUsers = db.UserSpaces.ToList().FindAll(us => us.spaceKey.Equals(id)).Select(s => s.user).ToList();
            alreadyUsers.Add(space.PI);
            ViewBag.Users = db.Users.ToList().Except(alreadyUsers);

            if(space == null)
            {
                return Redirect("../Dashboard");
            }
            UserSpace userspace = new UserSpace();
            userspace.space = db.Spaces.Find(id);
            userspace.spaceKey = userspace.space.key;
            return View(userspace);
        }