Ejemplo n.º 1
0
        public static User CreateUser(string login, string password, string email)
        {
            try
            {

                var db = new DatabaseEntities();
                var user = new User();

                user.Login = login;
                user.Password = Helper.GetMd5HashString(password);
                user.Email = email;

            //                user.Role = new Role();

                var role = from r in db.Roles where r.RoleName=="Registered" select r;

                user.Role = role.First();
                db.Users.Add(user);
                db.SaveChanges();
                return user;

            }
            catch
            {
                return null;
            }
        }
Ejemplo n.º 2
0
        public User ChangeUserPassword(User user, string newPassword)
        {
            user = _userRepository.ChangePassword(user, newPassword);

            _unitOfWork.Commit();

            return user;
        }
Ejemplo n.º 3
0
        public void AddHashToUser(User user, string hash)
        {
            HashKey key = new HashKey(hash) {UserId = user.Id};

            _keyRepository.Add(key);

            _unitOfWork.Commit();
        }
Ejemplo n.º 4
0
        public int GetEmployeeId(User user)
        {
            Employee employee = _employeeRepository.GetEmployees().FirstOrDefault(x => x.Agent_ID == user.RefId);

            if (employee != null)
            {
                return employee.Employee_ID;
            }
            else
            {
                return -1;
            }
        }
Ejemplo n.º 5
0
        public int Update(d.User newUser)
        {
            var entity = _context.Users.Find(newUser.UserId);

            entity.FirstName = newUser.FirstName;
            entity.LastName  = newUser.LastName;
            entity.Username  = newUser.UserName;
            entity.Pass      = newUser.PassWord;
            entity.City      = newUser.City;
            entity.State     = newUser.State;
            entity.Phone     = newUser.Phone;
            entity.Email     = newUser.Email;
            _context.Users.Update(entity);
            _context.SaveChanges();
            return(entity.UserId);
        }
Ejemplo n.º 6
0
        public int Add(d.User newUser)
        {
            var entity = new User
            {
                Username  = newUser.UserName,
                Pass      = newUser.PassWord,
                FirstName = newUser.FirstName,
                LastName  = newUser.LastName,
                Email     = newUser.Email,
                City      = newUser.City.ToLower(),
                State     = newUser.State,
                Phone     = newUser.Phone
            };

            _context.Users.Add(entity);
            _context.SaveChanges();
            return(entity.UserId);
        }
Ejemplo n.º 7
0
        public static User CreateUser(string login, string password,string email, int RoleId)
        {
            var db = new DatabaseEntities();
            var user = new User();

            user.Login = login;
            user.Password = Helper.GetMd5HashString(password);
            user.Email = email;

            //                user.Role = new Role();

            var role = from r in db.Roles where r.RoleId == RoleId select r;

            user.Role = role.First();
            db.Users.Add(user);
            db.SaveChanges();
            return user;
        }
Ejemplo n.º 8
0
        public async Task <UserAuthResult> Handle(AuthenticateUserCommand request, CancellationToken cancellationToken)
        {
            UserAuthResult userAuthResult   = null;
            var            db               = _instanceDB.Get <IUserDbManager>();
            var            base64EncodedPwd = Convert.FromBase64String(request.Password);
            var            passWord         = Encoding.UTF8.GetString(base64EncodedPwd);

            passWord = _hashHelper.GetMD5Hash(passWord);
            Domain.Models.User user = await db.AuthenticateUser(request.Name, passWord);

            if (user != null)
            {
                userAuthResult = new UserAuthResult
                {
                    AuthToken = _userAccessor.GenerateToken(user, _applicationSettingAccessor.Value.AuthenticationTokenSecret),
                    UserId    = user.Id
                };
            }
            return(userAuthResult);
        }
Ejemplo n.º 9
0
        public async Task AddCustomer_Database_TestAsync()
        {
            using var connection = new SqliteConnection("Data Source=:memory:");
            connection.Open();
            var options = new DbContextOptionsBuilder <mmpproject2Context>().UseSqlite(connection).Options;

            testUser = new Domain.Models.User("Grace", "Libardos", "*****@*****.**", "gl001", null);


            using (var context = new mmpproject2Context(options))
            {
                context.Database.EnsureCreated();
                var repo = new UserRepository(options);

                await repo.AddAsync(testUser);
            }

            using var context2 = new mmpproject2Context(options);
            DataAccess.Models.User userReal = context2.Users
                                              .Single(l => l.FirstName == "Grace");

            Assert.Equal(testUser.FirstName, userReal.FirstName);
            Assert.Equal(testUser.Email, userReal.Email);
        }
Ejemplo n.º 10
0
            public async Task <GetuserById.Response> Handle(GetuserById.Query request, CancellationToken cancellationToken)
            {
                Domain.Models.User user = await _repository.FindUserByIdAsync(request.Id);

                return(user == null ? null : new GetuserById.Response(user.Id, user.Name));
            }
Ejemplo n.º 11
0
        private void AddReportsToUser(User user)
        {
            var reports = _reportRepository.Get();

            foreach (var report in reports)
            {
                string output = string.IsNullOrEmpty(report.DefaultOutput) ? report.Output : report.DefaultOutput;

                UserReport userReport = new UserReport
                {
                    Output = output,
                    OutputConfiguration = GetOutputConfigurationFromOutput(output),
                    ReportId = report.Id,
                    User = user,
                };

                _userReportRepository.Add(userReport);
            }
        }
Ejemplo n.º 12
0
 private void AddOrUpdateUser(User user)
 {
     _userRepository.Add(user);
 }