Exemple #1
0
        public IAccountServiceResult Register(RegisterInputModel registerInputModel)
        {
            if (registerInputModel.Password != registerInputModel.PasswordHash)
            {
                return new LoginServiceResult {
                           OperationCode = OperationCode.ConfirmedError
                }
            }
            ;
            DatabaseContext databaseContext = new DatabaseContext();
            var             find            = databaseContext.Users.FirstOrDefault(x => x.Login == registerInputModel.Login);

            if (find != null)
            {
                return new LoginServiceResult {
                           OperationCode = OperationCode.FoundCopy
                }
            }
            ;
            var userNew = new User
            {
                Login        = registerInputModel.Login,
                PasswordHash = CryptService.MD5Hash(registerInputModel.Password),
                UserType     = registerInputModel.UserType,
                Name         = registerInputModel.Name
            };

            databaseContext.Add(userNew);
            databaseContext.SaveChanges();
            return(new LoginServiceResult
            {
                ActualID = userNew.ID,
                Login = userNew.Login,
                OperationCode = OperationCode.Success,
                UserType = userNew.UserType
            });
        }
    }
}
Exemple #2
0
        public IAccountServiceResult Login(LoginInputModels loginInputModels)
        {
            DatabaseContext databaseContext = new DatabaseContext();
            var             find            = databaseContext.Users.FirstOrDefault(x => x.Login == loginInputModels.Login &&
                                                                                   x.PasswordHash == CryptService.MD5Hash(loginInputModels.Password));

            if (find == null)
            {
                return new LoginServiceResult {
                           OperationCode = OperationCode.NotFound
                }
            }
            ;
            return(new LoginServiceResult
            {
                OperationCode = OperationCode.Success,
                ActualID = find.ID,
                Login = find.Login,
                UserType = find.UserType
            });
        }