Example #1
0
        private void ValidateLogin(UserAccountDataContext dc, string login)
        {
            var user = dc.Users.FirstOrDefault(u => u.Login == login);

            if (user != null)
            {
                throw new ServerSideException(String.Format(
                                                  "A user with the login name: {0}, already exists", login));
            }
        }
Example #2
0
        private void ValidateEmail(UserAccountDataContext dc, string email)
        {
            var user = dc.Users.FirstOrDefault(u => u.Email == email);

            if (user != null)
            {
                throw new ServerSideException(String.Format(
                                                  "This email: {0}, is already in use", email));
            }
        }
Example #3
0
        public void Handle(LogInCommand command)
        {
            using (var dbContext = new UserAccountDataContext())
            {
                User user = dbContext.Users.SingleOrDefault(u => u.Login == command.Login);
                ValidateLoginData(user, command);

                var appUser = CreateAppUserEntity(user);
                CookieHandler.Create(appUser, command.RememberMe);
            }
        }
        public ActionResult ChangeRole()
        {
            ChangeUserRoleViewModel model;
            var user = System.Web.HttpContext.Current.GetCurrentUser();

            using (var dbContext = new UserAccountDataContext())
            {
                model = dbContext.Users.GetUserRole(user.UserId);
            }

            return(View(model));
        }
        public ActionResult ChangeData()
        {
            ChangeUserDataViewModel model;
            var user = System.Web.HttpContext.Current.GetCurrentUser();

            using (var dbContext = new UserAccountDataContext())
            {
                model = dbContext.Users.GetUserData(user.UserId);
            }

            return View(model);
        }
Example #6
0
        public void Handle(ConfirmAccountCommand command)
        {
            using (var dbContext = new UserAccountDataContext())
            {
                User user = dbContext.Users.SingleOrDefault(u => u.ConfirmGuid == command.ConfirmGuid);

                if (user == null)
                {
                    throw new ServerSideException("User not find, check your activate link and try agine, or contact us");
                }

                user.ConfirmAccount();
            }
        }
Example #7
0
        public void Handle(UpdateUserAddressCommand command)
        {
            using (var dbContext = new UserAccountDataContext())
            {
                User user = dbContext.Users.SingleOrDefault(u => u.Id == command.UserId);

                if (user == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                UpdateUserAddres(user.Address, command);
                dbContext.SaveChanges();
            }
        }
Example #8
0
        public void Handle(AddUserCommand command)
        {
            ValidateCommandParameters(command);

            using (var dbContext = new UserAccountDataContext())
            {
                ValidateLogin(dbContext, command.Login);
                ValidateEmail(dbContext, command.Email);

                User user = CreateUserEntity(command);
                dbContext.Users.Add(user);
                dbContext.SaveChanges();

                // TODO add event: User registered - send confirm email
            }
        }
Example #9
0
        public void Handle(UpdateUserDataCommand command)
        {
            ValidatePhoneNumber(command.Phone);

            using (var dbContext = new UserAccountDataContext())
            {
                User user = dbContext.Users.Single(u => u.Id == command.Id);

                if (user == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                UpdateUserEntity(user, command);
                dbContext.SaveChanges();
            }
        }
Example #10
0
        public void Handle(ChangeUserRoleCommand command)
        {
            using (var dbContext = new UserAccountDataContext())
            {
                User user = dbContext.Users.SingleOrDefault(u => u.Id == command.UserId);

                if (user == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                // TODO Check if user have league or team
                // if user have league or team then cant change role

                ChangeRole(user, command);
                dbContext.SaveChanges();
            }
        }
Example #11
0
        public void Handle(ChangePasswordCommand command)
        {
            ValidatePasswordConfirm(command.NewPassword, command.NewPasswordRepeat);

            using (var dbContext = new UserAccountDataContext())
            {
                User user = dbContext.Users.SingleOrDefault(u => u.Id == command.UserId);

                if (user == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                ChangePassword(user, command);
                dbContext.SaveChanges();

                // TODO add event: User changed password - send email with new password
            }
        }
Example #12
0
        public void Handle(RemoveUserCommand command)
        {
            using (var dbContext = new UserAccountDataContext())
            {
                User user = dbContext.Users.SingleOrDefault(u => u.Id == command.UserId);

                if (user == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                // TODO Check if user have league or team
                // if user have league or team then cant delete account
                dbContext.Users.Remove(user);
                dbContext.SaveChanges();

                // TODO create event - user removed - LogOff
            }
        }
Example #13
0
        public void Handle(ChangeEmailCommand command)
        {
            ValidateCommandParameters(command);

            using (var dbContext = new UserAccountDataContext())
            {
                User user = dbContext.Users.SingleOrDefault(u => u.Id == command.UserId);

                if (user == null)
                {
                    throw new ServerSideException("Ups, something went wrong! Refresh page and try agine");
                }

                ChangeEmail(user, command);
                dbContext.SaveChanges();

                // TODO add event: User email changed - send confirm email
            }
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var userAccountDataContext = new UserAccountDataContext();
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<UserAccountDataContext, UsersAccounts.Model.Migrations.Configuration>());
            userAccountDataContext.Database.Initialize(false);

            var managementDataContext = new ManagementDataContext();
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<ManagementDataContext, Management.Model.Migrations.Configuration>());
            managementDataContext.Database.Initialize(false);

            var leagueDataContext = new LeagueDataContext();
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<LeagueDataContext, League.Model.Migrations.Configuration>());
            leagueDataContext.Database.Initialize(false);

            BootstrapContexts();
        }
Example #15
0
        public void Handle(ForgotPasswordCommand command)
        {
            if (!IsValidEmail(command.Email))
            {
                throw new ServerSideException("Email format is invalid");
            }

            using (var dbContext = new UserAccountDataContext())
            {
                var user = dbContext.Users.SingleOrDefault(u => u.Email == command.Email);

                if (user == null)
                {
                    throw new ServerSideException(
                              String.Format("User with email: {0} does not exist", command.Email));
                }

                // TODO Generate new password
                // TODO Send email with new password
            }
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var userAccountDataContext = new UserAccountDataContext();

            Database.SetInitializer(new MigrateDatabaseToLatestVersion <UserAccountDataContext, UsersAccounts.Model.Migrations.Configuration>());
            userAccountDataContext.Database.Initialize(false);

            var managementDataContext = new ManagementDataContext();

            Database.SetInitializer(new MigrateDatabaseToLatestVersion <ManagementDataContext, Management.Model.Migrations.Configuration>());
            managementDataContext.Database.Initialize(false);

            var leagueDataContext = new LeagueDataContext();

            Database.SetInitializer(new MigrateDatabaseToLatestVersion <LeagueDataContext, League.Model.Migrations.Configuration>());
            leagueDataContext.Database.Initialize(false);

            BootstrapContexts();
        }
Example #17
0
 public LoginDataAccess(UserAccountDataContext context)
 {
     this._context = context;
 }
Example #18
0
 public GenerateNewPasswordDataAccess(UserAccountDataContext context)
 {
     this._context = context;
 }
Example #19
0
 public OutboxDataAccess(UserAccountDataContext context)
 {
     this._context = context ?? throw new ArgumentNullException(nameof(context));
 }
Example #20
0
 public CreateNewAccountDataAccess(UserAccountDataContext context)
 {
     this._context = context;
 }