Esempio n. 1
0
        public ActionResult MassCreate(string familyNames, int?contestId)
        {
            var lines   = familyNames.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            var contest = contestId == null ? null : session.Load <Contest>(contestId);

            var res = new List <Tuple <string, User> >();

            foreach (var line in lines)
            {
                var password = StringUtils.GenerateRandomLatinString(GeneratedUserNameAndPasswordLength);
                var userName = StringUtils.GenerateRandomLatinString(GeneratedUserNameAndPasswordLength);

                var user = new User {
                    DisplayName = line, UserName = userName, Password = new Password(password)
                };
                session.Save(user);
                interceptor.OnCreated(user);


                if (contest != null)
                {
                    var application = new ParticipationApplication
                    {
                        Contest     = contest,
                        IsApproved  = true,
                        SubmittedAt = clock.CurrentTime,
                        User        = user
                    };
                    session.Save(application);
                }

                res.Add(Tuple.Create(password, user));
            }
            return(View(res));
        }
Esempio n. 2
0
        public ActionResult Create(int id)
        {
            var application = new ParticipationApplication
            {
                Contest     = session.Load <Contest>(id),
                User        = userSession.CurrentUser,
                SubmittedAt = clock.CurrentTime,
                IsApproved  = false
            };

            session.Save(application);
            return(this.RedirectToAction <ContestController>(x => x.View(id)));
        }
Esempio n. 3
0
        public void OnIsApprovedChanged(ParticipationApplication application, bool oldIsApproved)
        {
            if (application.IsApproved == oldIsApproved)
            {
                return;
            }

            var contestParticipants = UserGroups.ContestParticipants(application.Contest);

            if (application.IsApproved)
            {
                authz.AssociateUserWith(application.User, contestParticipants);
            }
            else
            {
                authz.DetachUserFromGroup(application.User, contestParticipants);
            }
        }