Exemplo n.º 1
0
        public void Register(RegisterCommand command)
        {
            ISecurityUtility securityUtility = new SecurityUtility();

            ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.UserName), String.Format(ErrorMessage.IsRequired, "Tên đăng nhập"));
            ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.Password), String.Format(ErrorMessage.IsRequired, "Mật khẩu"));
            var user = securityUtility.GetUserByUsername(command.UserName);

            ThrowError.Against <ArgumentException>(user != null, String.Format(ErrorMessage.Exists, "Tên đăng nhập"));
            ThrowError.Against <ArgumentException>(_personService.Query(t => t.Email == command.Email).Select().Any(), String.Format(ErrorMessage.Exists, "Email"));

            // ThrowError.Against<ArgumentException>(!securityUtility.IsPasswordValid(command.Password), String.Format(ErrorMessage.IsPassword));

            var person = new Person()
            {
                Email    = command.Email,
                FullName = command.FullName,
                PersonId = Guid.NewGuid()
            };

            user = new User()
            {
                Type         = command.Type,
                UserName     = command.UserName,
                CreationDate = DateTime.Now,
                Locked       = false,
                PersonId     = person.PersonId,
                Password     = Cryptography.EncryptPassword(command.Password, "")
            };

            _unitOfWork.Repository <Domain.Entity.User>().Insert(user);
            _personService.Insert(person);
            _unitOfWork.SaveChanges();
        }
Exemplo n.º 2
0
        public void ResetPassword(ResetPasswordCommand command)
        {
            ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.PasswordNew), "Vui lòng nhập mật khẩu mới.");

            var user =
                _unitOfWork.Repository <Domain.Entity.User>()
                .Query(u => u.PersonId == command.PersonId)
                .Select()
                .FirstOrDefault();

            user.Password = Cryptography.EncryptPassword(command.PasswordNew, "");
            user.Locked   = false;
            _unitOfWork.Repository <Domain.Entity.User>().Update(user);
            _unitOfWork.SaveChanges();
        }
Exemplo n.º 3
0
        public void ChangePassword(ChangePasswordCommand command)
        {
            ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.PasswordOld), "Vui lòng nhập mật khẩu cũ.");
            ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.PasswordNew), "Vui lòng nhập mật khẩu mới.");

            var user =
                _unitOfWork.Repository <Domain.Entity.User>()
                .Query(u => u.PersonId == command.PersonId && u.Password == Cryptography.EncryptPassword(command.PasswordOld, ""))
                .Select()
                .FirstOrDefault();

            ThrowError.Against <ApplicationException>(user == null, string.Format("Mật khẩu cũ không đúng."));
            user.Password = Cryptography.EncryptPassword(command.PasswordNew, "");
            user.Locked   = false;
            _unitOfWork.Repository <Domain.Entity.User>().Update(user);
            _unitOfWork.SaveChanges();
        }
Exemplo n.º 4
0
        public void EditTypeMember(EditTypeMemberCommand command)
        {
            ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.Name), String.Format(ErrorMessage.IsRequired, "Tên"));
            ThrowError.Against <ArgumentException>(_typeMemberService.Query(t => t.Name.ToUpper().Trim() == command.Name.ToUpper().Trim() && t.TypeMemberId != command.TypeMemberId).Select().Any(), String.Format(ErrorMessage.Exists, "Tên"));

            var count = _typeMemberService.Query(t => t.TypeMemberId != command.TypeMemberId && ((t.ScoresFrom < command.ScoresFrom && command.ScoresFrom < t.ScoresTo) || (t.ScoresFrom < command.ScoresTo && command.ScoresTo < t.ScoresTo) || (command.ScoresFrom < t.ScoresFrom && t.ScoresFrom < command.ScoresTo) || (command.ScoresFrom < t.ScoresTo && t.ScoresTo < command.ScoresTo) || (command.ScoresFrom == t.ScoresFrom && command.ScoresTo == t.ScoresTo))).Select().Count();

            ThrowError.Against <ArgumentException>(count > 0, String.Format(ErrorMessage.IsNotTypemMember));

            var typeMember = _typeMemberService.Find(command.TypeMemberId);

            typeMember.Name = command.Name;
            typeMember.PercentDownPayment = command.PercentDownPayment;
            typeMember.ScoresFrom         = command.ScoresFrom;
            typeMember.ScoresTo           = command.ScoresTo;
            _typeMemberService.Update(typeMember);
            _unitOfWork.SaveChanges();
        }
Exemplo n.º 5
0
        public Guid AddTypeMember(AddTypeMemberCommand command)
        {
            ThrowError.Against <ArgumentException>(string.IsNullOrEmpty(command.Name), String.Format(ErrorMessage.IsRequired, "Tên"));
            ThrowError.Against <ArgumentException>(_typeMemberService.Query(t => t.Name.ToUpper().Trim() == command.Name.ToUpper().Trim()).Select().Any(), String.Format(ErrorMessage.Exists, "Tên"));

            var count = _typeMemberService.Query(t => ((t.ScoresFrom < command.ScoresFrom && command.ScoresFrom < t.ScoresTo) || (t.ScoresFrom < command.ScoresTo && command.ScoresTo < t.ScoresTo) || (command.ScoresFrom < t.ScoresFrom && t.ScoresFrom < command.ScoresTo) || (command.ScoresFrom < t.ScoresTo && t.ScoresTo < command.ScoresTo) || (command.ScoresFrom == t.ScoresFrom && command.ScoresTo == t.ScoresTo))).Select().Count();

            ThrowError.Against <ArgumentException>(count > 0, String.Format(ErrorMessage.IsNotTypemMember));

            var typeMember = new TypeMember()
            {
                Name = command.Name,
                PercentDownPayment = command.PercentDownPayment,
                ScoresFrom         = command.ScoresFrom,
                ScoresTo           = command.ScoresTo,
                TypeMemberId       = Guid.NewGuid()
            };

            _typeMemberService.Insert(typeMember);
            _unitOfWork.SaveChanges();
            return(typeMember.TypeMemberId);
        }