Exemplo n.º 1
0
        public ResponseDto RegisterUser(UserDto user)
        {
            AccountTDataAccess accountDa = new AccountTDataAccess();
            ResponseDto        response  = new ResponseDto();

            try
            {
                if (ValidateNewUser(user))
                {
                    bool existUser = ((SecurityUserTDataAccess)this.dataAccess).ExistUser(user);
                    if (!existUser)
                    {
                        if (user.Accounts.Count() > 0)
                        {
                            var account      = user.Accounts.FirstOrDefault();
                            var existAccount = accountDa.ExistAccount(account.Username);
                            if (!existAccount)
                            {
                                this.Insert(user);
                                foreach (var newAccount in user.Accounts)
                                {
                                    newAccount.UserId = user.UserId;
                                }
                                try
                                {
                                    accountDa.Insert(user.Accounts.ToList());
                                }
                                catch
                                {
                                    accountDa.Delete(user.Accounts.ToList());
                                    this.Delete(user);
                                    response.Response.AddBusinessException("ثبت کاربر جدید با شکست مواجه شد!", BusinessExceptionEnum.Operational);
                                }
                            }
                            else
                            {
                                response.Response.AddBusinessException("کاربر با این حساب کاربری قبلا ثبت شده است!", BusinessExceptionEnum.Validation);
                            }
                        }
                        else
                        {
                            response.Response.AddBusinessException("کاربر باید دارای حساب کاربری پیش فرض باشد!", BusinessExceptionEnum.Validation);
                        }
                    }
                    else
                    {
                        response.Response.AddBusinessException("!کاربر با این کد ملی قبلا ثبت شده است", BusinessExceptionEnum.Validation);
                    }
                }
                else
                {
                    response.SetResponse(user.Response);
                }
            }
            catch (Exception ex)
            {
                response.Response.AddBusinessException(ex.Message, BusinessExceptionEnum.Operational);
            }

            return(response);
        }