public ActionResult Edit(TeamEditModel response)
        {
            if (response.Team == null || response.Team.TeamID == Guid.Empty) return HttpNotFound();

            Team Team = reposetory.GetTeam(response.Team.TeamID);
            if (Team == null) return HttpNotFound();
            int minTeammembers = int.Parse(ConfigurationManager.AppSettings["TeamMin"]);
            int maxTeammembers = int.Parse(ConfigurationManager.AppSettings["TeamMax"]);
            if (response.Start < Team.Folder.Start | response.Start > Team.Folder.Finish)
            {
                ModelState.AddModelError("Team.Start", General.ErrorStartNotWithinFolderDate);
                ModelState.SetModelValue("Team.Start", new ValueProviderResult(Team.Start, Team.Start.ToString(), CultureInfo.InvariantCulture));
            }
            if (response.Team.Trial && response.Teammembers != null && response.Teammembers.Where(x => x != Guid.Empty).Count() >= maxTeammembers - 1) ModelState.AddModelError("", General.ErrorTrialToManyTeammembers);

            if (ModelState.IsValid)
            {
                Team.Start = response.Start;
                //Team.Duration = response.Team.Duration;
                //Team.Location = response.Team.Location;
                Team.Note = response.Team.Note;
                Team.Star = response.Team.Star;
                Team.Status = response.Team.Status;
                Team.Trial = response.Team.Trial;
                Team.TrialInfo = response.Team.TrialInfo;
                Team.TeamLeaderId = response.TeamLeader;

                Team.Teammembers = new List<Person>();
                if (response.Teammembers != null)
                {
                    foreach (Guid p in response.Teammembers.Where(x => x != Guid.Empty).Distinct())
                    {
                        Person dbP = reposetory.GetPerson(p);
                        if (dbP != null && Team.Teammembers.Count() < maxTeammembers) Team.Teammembers.Add(dbP);
                    }
                }
                Person TeamLeader = reposetory.GetPerson(Team.TeamLeaderId);
                if (TeamLeader != null) Team.Teammembers.Add(TeamLeader);
                if (reposetory.SaveTeam(Team))
                {
                    ViewBag.FormSucces = true;
                    ModelState.Clear();
                    Notification not = reposetory.Notify(Team, String.Format(Notifications.TeamChanged));
                    reposetory.NotifyAddPlanner(not, Team.Association.AssociationID);
                    reposetory.NotifyAddTeam(not, Team);
                    reposetory.NotifySave(not);
                    //if (TempData["ReturnUrl"] != null) return Redirect(((Uri)TempData["ReturnUrl"]).ToString());
                }
            }

            var Active = reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID).Select(d => new SelectListItem { Value = d.Person.PersonID.ToString(), Text = d.Person.FullName }).ToList();
            Active.Insert(0, new SelectListItem { Value = Guid.Empty.ToString(), Text = General.DropDownChoose });
            response.Teammembers = response.Teammembers == null ? new List<Guid>() : response.Teammembers = response.Teammembers.Where(x => x != Guid.Empty).Distinct().ToList();
            int EmptyAdd = maxTeammembers - response.Teammembers.Count - 1; // (response.Team.Trial ? 2 : 1);
            for (var i = 0; i < EmptyAdd; i++)
            {
                response.Teammembers.Add(Guid.Empty);
            }
            response.Team = Team;
            response.Active = Active;
            response.minTeammembers = minTeammembers;
            response.maxTeammembers = maxTeammembers;

            return View(response);
        }
        public ActionResult Edit(Guid Id)
        {
            if (Request.IsLocal) TempData["ReturnUrl"] = Request.UrlReferrer;
            Team Team = reposetory.GetTeam(Id);
            if (Team == null) return HttpNotFound();
            int minTeammembers = int.Parse(ConfigurationManager.AppSettings["TeamMin"]);
            int maxTeammembers = int.Parse(ConfigurationManager.AppSettings["TeamMax"]);

            var Active = reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID).Select(d => new SelectListItem { Value = d.Person.PersonID.ToString(), Text = d.Person.FullName }).ToList();
            Active.Insert(0, new SelectListItem { Value = Guid.Empty.ToString(), Text = General.DropDownChoose });
            TeamEditModel Model = new TeamEditModel
            {
                Team = Team,
                Active = Active,
                TeamLeader = Team.TeamLeaderId,
                Teammembers = new List<Guid>(),
                minTeammembers = minTeammembers,
                maxTeammembers = maxTeammembers
            };
            foreach (Person P in Team.Teammembers ?? new List<Person>())
            {
                if (P.PersonID != Team.TeamLeaderId) Model.Teammembers.Add(P.PersonID);
            }
            int EmptyAdd = maxTeammembers - Model.Teammembers.Count - 1; // (Team.Trial ? 2 : 1);
            for (var i = 0; i < EmptyAdd; i++)
            {
                Model.Teammembers.Add(Guid.Empty);
            }


            return View(Model);
        }