コード例 #1
0
        public void DeleteUserTotally(int userId, UserManager <MyMeetupUser> userManager)
        {
            var registrations = _context.Registrations.Where(x => x.UserId == userId).ToList();

            _context.RemoveRange(registrations);
            _context.SaveChanges();
            MyMeetupUser user   = userManager.Users.First(x => x.Id == userId);
            var          result = userManager.DeleteAsync(user).Result;
        }
コード例 #2
0
        public void ModifyUser(MyMeetupUser model)
        {
            var user = _context.Users.Single(x => x.Id == model.Id);

            user.FirstName            = model.FirstName;
            user.LastName             = model.LastName;
            user.Email                = model.Email;
            user.IsOkToGetMeetupsInfo = model.IsOkToGetMeetupsInfo;
            _context.SaveChanges();
        }
コード例 #3
0
ファイル: MyMeetupUser.cs プロジェクト: guillaumejay/MyMeetup
        internal static int?CreateUser(MyMeetupUser user, string role, string password, UserManager <MyMeetupUser> userManager)
        {
            IdentityResult result = userManager.CreateAsync(user, password).Result;

            if (result.Succeeded)
            {
                userManager.AddToRoleAsync(user, role).Wait();
                user = userManager.FindByNameAsync(user.UserName).Result;
                return(user.Id);
            }

            return(null);
        }
コード例 #4
0
        public ResultAddRegularUser AddRegularUser(SigninMeetupModel model, int?meetupIdToRegister, UserManager <MyMeetupUser> userManager)
        {
            ResultAddRegularUser rau     = new ResultAddRegularUser();
            MyMeetupUser         newUser = MyMeetupUser.From(model);

            rau.UserId = MyMeetupUser.CreateUser(newUser, MyMeetupRole.Participant,
                                                 newUser.Initials +
                                                 DateTime.Now.ToString("HHmmss"), userManager);
            if (rau.UserOk && meetupIdToRegister.HasValue)
            {
                rau.RegistrationCode = Register(newUser, meetupIdToRegister.Value).RegistrationCode;
            }

            return(rau);
        }
コード例 #5
0
ファイル: Seeding.cs プロジェクト: guillaumejay/MyMeetup
 public static void SeedUsers(UserManager <MyMeetupUser> userManager)
 {
     if (userManager.FindByNameAsync("admin").Result == null)
     {
         var user = new MyMeetupUser
         {
             UserName       = "******",
             Email          = "*****@*****.**",
             FirstName      = "test",
             LastName       = "test2",
             LockoutEnabled = false
         };
         string pwd = $"admin{DateTime.Now:yyMMdd}";
         MyMeetupUser.CreateUser(user, MyMeetupRole.Administrateur, pwd, userManager);
     }
 }
コード例 #6
0
        public Registration Register(MyMeetupUser user, int meetupId, bool ignoreMeetupRegistrationValidity = false)
        {
            Meetup m = _context.Meetups.AsNoTracking().FirstOrDefault(x => x.Id == meetupId);

            if (m == null)
            {
                return(null);
            }

            if (!ignoreMeetupRegistrationValidity)
            {
                if (m.IsVisible == false)
                {
                    return(null);
                }

                if (m.OpenForRegistrationOn == null)
                {
                    return(null);
                }

                if (m.OpenForRegistrationOn.Value > DateTime.UtcNow)
                {
                    return(null);
                }
            }
            Registration r =
                new Registration(user.Id, meetupId)
            {
                RegistrationCode = Registration.CreateCode(user.Id, meetupId)
            };

            _context.Registrations.Add(r);
            _context.SaveChanges();
            return(r);
        }