Пример #1
0
        public MessageResponse Register(string language, UserRegisterRequest request)
        {
            ValidationResponse validationResponse = Validat <UserRegisterRequest>(_validator, request, language);

            if (validationResponse == null)
            {
                if (_work.EmailIsExist(request.Email))
                {
                    throw new TranslationException(_translator, language, ConstentMessages.EmailIsExist, null);
                }
                //if (_work.UserNameIsExist(request.UserName))
                //    throw new TranslationException(_translator, language, ConstentMessages.UserNameIsExist, null);
                string errorMessageKey = "";
                try
                {
                    errorMessageKey = ConstentMessages.LoadRoleError;
                    string roleId = _work.LoadRoleId(EnumData.Role.Manager.ToString());
                    errorMessageKey = ConstentMessages.SaveUserError;
                    _work.InserUser(request.UserName, request.Password, request.Email, roleId);
                    return(new MessageResponse {
                        Message = "OK"
                    });
                }
                catch (Exception ex)
                {
                    throw new TranslationException(_translator, language, errorMessageKey, ex);;
                }
            }
            else
            {
                throw new MessagesException(validationResponse.Messages);
            }
        }
Пример #2
0
        public IdResponse Insert(string language, string sessionId, UserRequest request)
        {
            AppUser admin = this.LoadUserWithSessionId(sessionId);

            ValidateSessionAndRight(language, admin, EnumData.AppModules.AppUser.ToString(), new List <string> {
                EnumData.RoleRight.all.ToString(), EnumData.RoleRight.account.ToString()
            });
            ValidationResponse validationResponse = Validat <UserRequest>(_userValidator, request, language);

            if (validationResponse != null)
            {
                throw new MessagesException(validationResponse.Messages);
            }
            if (_work.EmailIsExist(request.Email))
            {
                throw new TranslationException(_translator, language, ConstentMessages.EmailIsExist, null);
            }
            if (_work.UserNameIsExist(request.UserName))
            {
                throw new TranslationException(_translator, language, ConstentMessages.UserNameIsExist, null);
            }

            string errorMessageKey = "";

            try
            {
                errorMessageKey = ConstentMessages.ServerError;
                string password = _passwordService.Generate();
                string subject  = _translator[language, ConstentMessages.EmailCreateSuject];
                string body     = _translator[language, ConstentMessages.EmailCreateBody, password];
                _emailService.Send(request.Email, subject, body);
                AppUser user = CreateUserFromUserRequest(request, password);
                user.AccountUserId = user.Id;
                _work.InserUser(user);
                this.UpdateAdminSession(admin);
                return(new IdResponse {
                    Id = user.Id, SessionId = admin.Session.Id, SessionUpdateTs = admin.Session.UpdateTs.ToJsTime()
                });
            }
            catch (Exception ex)
            {
                throw new TranslationException(_translator, language, errorMessageKey, ex);
            }
        }