コード例 #1
0
        public void Create(string email, string password)
        {
            WorkerUserDTO existsUser = getUserDTO(u => u.Email.ToUpper() == email.ToUpper());

            if (existsUser != null)
            {
                setErrorMsg("Email", Resource.UniqueEmailConstraintMsg);
            }

            if (!FormatConfirm.IsEmail(email))
            {
                setErrorMsg("Email", Resource.EmailConstraintMsg);
            }


            checkStringConstraint("Password", password, true, 100, 5);

            if (errorMessages.Count > 0)
            {
                throw new DataServiceException(Resource.GeneralConstraintMsg, errorMessages);
            }


            WorkerUser user = new WorkerUser()
            {
                Email    = email,
                Password = password
            };

            userRepository.Save(user);

            repository.SaveChanges();
        }
コード例 #2
0
        public void Save(WorkerUserDTO dto)
        {
            if (dto.Id == 1)
            {
                throw new DataServiceException(Resource.SuperUserUpdateMsg);
            }

            checkStringConstraint("Name", dto.Name, true, 100, 5);
            checkStringConstraint("Email", dto.Email, true, 100, 5);
            checkStringConstraint("Password", dto.Password, true, 100, 5);

            if (!String.IsNullOrWhiteSpace(dto.Email))
            {
                WorkerUserDTO existsUser = getUserDTO(u => u.Email.ToUpper() == dto.Email.ToUpper() && u.Id != dto.Id);
                if (existsUser != null)
                {
                    setErrorMsg("Email", Resource.UniqueEmailConstraintMsg);
                }

                if (!FormatConfirm.IsEmail(dto.Email))
                {
                    setErrorMsg("Email", Resource.EmailConstraintMsg);
                }
            }

            if (dto.UserType == null || dto.UserType.Id == 0)
            {
                setErrorMsg("UserType", Resource.EmptyConstraintMsg);
            }

            if (errorMessages.Count > 0)
            {
                throw new DataServiceException(Resource.GeneralConstraintMsg, errorMessages);
            }

            WorkerUser user = null;

            if (dto.Id == 0)
            {
                user = new WorkerUser();
            }
            else
            {
                user = userRepository.Get(dto.Id);
            }

            user.Email    = dto.Email;
            user.Password = dto.Password;
            user.Name     = dto.Name;
            user.UserType = typeWorkerUserRepository.Get(dto.UserType.Id);
            user.Disabled = dto.Disabled;

            userRepository.Save(user);
            repository.SaveChanges();
        }