public ActionResult Create(int[] time_ids, DateTime date ,int[] locationId,int ClubId, int? SubEventId)
        {
            List<Club> club_list = RoleHelper.GetRoleClub(User.Identity.Name, "会长");
            if (club_list == null)
            {
                return View("PermissionDeniedError");
            }
            ViewBag.ClubId = new SelectList(club_list, "Id", "Id");

            LocationApplication location_application = new LocationApplication();
            location_application.Times = new List<Time>();
            foreach (var time_id in time_ids)
            {
                var t = unitOfWork.Times.Find(time_id);
                location_application.Times.Add(t);
            }
            location_application.Date = date;
            if (SubEventId != null)
            {
                location_application.SubEvent = unitOfWork.SubEvents.Find(SubEventId);
            }
            location_application.Club = unitOfWork.Clubs.Find(ClubId);
            location_application.Locations = new List<Location>();
            foreach (var id in locationId)
            {
                location_application.Locations.Add(unitOfWork.Locations.Find(id));
            }
            location_application.ApplicantUserName = User.Identity.Name;
            location_application.Status = Application.NOT_VERIFIED;
            unitOfWork.Applications.Add(location_application);
            unitOfWork.SaveChanges();

            //if (!ScmRoleProvider.HasMembershipIn(ClubId, null, new string[] { "会长" }))
            //{

            //}

            return RedirectToAction("Index", "Location");
        }
        public LocationApplication JoinLocations(LocationApplication application)
        {
            IDictionary<int, Location> location_occurance_counter = new Dictionary<int, Location>();
            List<Location> joined_locations = new List<Location>();

            foreach (Location location in application.Locations)
            {
                if (!location_occurance_counter.ContainsKey(location.Id))
                    location_occurance_counter.Add(new KeyValuePair<int, Location>(location.Id, null));

                location_occurance_counter[location.Id] = location;
            }

            foreach (var location in location_occurance_counter)
            {
                joined_locations.Add(location.Value);
            }

            application.Locations = joined_locations;

            return application;
        }
        public void VerifyLocationApplication(LocationApplication application, bool is_passed, bool save)
        {
            if (is_passed)
            {
                application.Status = Application.PASSED;

                LocationAssignment assignment = new LocationAssignment
                {
                    ApplicantUserName = application.ApplicantUserName,
                    ClubId = application.ClubId ?? 0,
                    Date = application.ApplicatedDate,
                    Locations = application.Locations,
                    Times = application.Times
                };

                application.Assignment = assignment;
            }
            else
            {
                application.Status = Application.FAILED;
            }

            if (save)
                db.SaveChanges();
        }
        public void UpdateLocationApplication(LocationApplication orig_application, LocationApplication new_application)
        {
            orig_application.ApplicatedDate = orig_application.SubEvent.Date;
            orig_application.Date = DateTime.Now;

            UpdateTimes(orig_application.Times, orig_application.SubEvent.Times);

            orig_application.Locations.Clear();

            ICollection<Location> collection = new_application.Locations.ToList();
            var locations = db.Locations.ToList().ToList().Where(t => collection.Any(s => s.Id == t.Id));

            foreach (Location location in locations)
            {
                orig_application.Locations.Add(location);
            }
        }
        public void NewLocationApplication(LocationApplication application, SubEvent sub_event, bool no_add = true, bool save = false)
        {
            application.Id = db.GenerateIdFor(IdentityForTPC.APPLICATION);
            application.ApplicantUserName = sub_event.Event.ChiefEventOrganizerId;
            application.ApplicatedDate = sub_event.Date;
            application.ClubId = sub_event.Event.ClubId;
            application.Date = DateTime.Now;
            application.Status = Application.NOT_SUBMITTED;
            application.SubEvent = sub_event;
            application.Times = sub_event.Times;

            ICollection<Location> collection = application.Locations.ToList();
            var locations = db.Locations.ToList().ToList().Where(t => collection.Any(s => s.Id == t.Id));

            application.Locations.Clear();
            foreach (Location location in locations)
            {
                application.Locations.Add(location);
            }

            if (!no_add)
                sub_event.LocationApplications.Add(application);

            if (save)
                db.SaveChanges();
        }