Exemplo n.º 1
0
        public Task <int> UpdateAsync(string id, AccountInputDto inputDto)
        {
            var model = inputDto.MapTo <TAccount>();

            model.Id = id;
            return(_repository.UpdateAsync(model));
        }
Exemplo n.º 2
0
        public void AddStaticAccount()
        {
            var payload = new AccountInputDto
            {
                Description = "Equity Again Swap - ACX AU SWAP - GSCO - MSCO",
                Type        = 3,
                Tags        = new List <AccountTagInputDto>(new[]
                {
                    new AccountTagInputDto {
                        Id = 2, Value = "Equity"
                    },
                    new AccountTagInputDto {
                        Id = 4, Value = "ACX AU SWAP"
                    }
                })
            };

            var accounts = Utils.PostWebApi("FinanceWebApi", $"{AccountsUrl}", payload);

            Task.WaitAll(accounts);

            var response = JsonConvert.DeserializeObject <Response>(accounts.Result);

            Assert.IsTrue(response.isSuccessful, "Account Added");
        }
Exemplo n.º 3
0
        public async Task AddDynamicAccount()
        {
            var accountCategories = await GetList <AccountCategoryOutputDto>(AccountCategoriesUrl);

            var accountTypes =
                await GetList <AccountTypeOutputDto>(
                    $"{AccountTypesUrl}?accountCategoryId={accountCategories.FirstOrDefault()?.Id}");

            var accountTags = await GetList <AccountTagOutputDto>(AccountTagsUrl);

            var payload = new AccountInputDto
            {
                Description = accountTypes.FirstOrDefault()?.Name,
                Type        = accountTypes.FirstOrDefault()?.Id,
                Tags        = new List <AccountTagInputDto>(new[]
                {
                    new AccountTagInputDto
                    {
                        Id = accountTags.FirstOrDefault()?.Id, Value = accountCategories.FirstOrDefault()?.Name
                    }
                })
            };

            var accounts = Utils.PostWebApi("FinanceWebApi", $"{AccountsUrl}", payload);

            Task.WaitAll(accounts);

            var response = JsonConvert.DeserializeObject <Response>(accounts.Result);

            Assert.IsTrue(response.isSuccessful, "Account Added");
        }
Exemplo n.º 4
0
        public async Task <bool> UserVilidata(AccountInputDto data)
        {
            if (string.IsNullOrEmpty(data.AccountNumber) || string.IsNullOrEmpty(data.PassWord))
            {
                return(false);
            }
            var entity = await _accountRepository.FirstOrDefaultAsync(s => s.AccountNumber == data.AccountNumber && s.PassWord == Common.GetMD5(data.PassWord));

            return(entity != null);
        }
Exemplo n.º 5
0
        public async Task <bool> SaveAccountPWD(AccountInputDto data)
        {
            var entity = await _accountRepository.FirstOrDefaultAsync(s => s.AccountNumber == data.AccountNumber);

            if (entity == null)
            {
                return(false);
            }
            entity.UpdateTime  = DateTime.Now;
            entity.OldPassWord = entity.PassWord;
            entity.PassWord    = Common.GetMD5(data.PassWord);
            return(await _accountRepository.CommitAsync() > 0);
        }
        public async Task <AccountResponseDto> Post(AccountInputDto input)
        {
            //Check for validity
            if (!input.IsValid())
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = "Input data is invalid."
                });
            }

            var result = await Services.User.RegisterUser(input.AccountId);

            return(new AccountResponseDto(result));
        }
Exemplo n.º 7
0
        public void AddInvalidAccount()
        {
            var payload = new AccountInputDto
            {
                Description = "",
                Type        = 0,
                Tags        = new List <AccountTagInputDto>()
            };

            var accounts = Utils.PostWebApi("FinanceWebApi", $"{AccountsUrl}", payload);

            Task.WaitAll(accounts);

            var response = JsonConvert.DeserializeObject <Response>(accounts.Result);

            Assert.IsTrue(response.isSuccessful == false, "Account not Added");
        }
Exemplo n.º 8
0
        public async Task <IActionResult> OnGetAsync()
        {
            var account = (await _accountService.GetFilteredAsync(
                               new AccountQueryModel
            {
                Id = Guid.Parse(RouteData.Values["id"]?.ToString()),
                ApplicationUserId = HttpContext.User.Claims
                                    .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value
            })).FirstOrDefault();

            if (account == null)
            {
                return(NotFound());
            }

            InputDto = _mapper.Map <AccountInputDto>(account);

            return(Page());
        }
Exemplo n.º 9
0
        public async Task <AccountDto> CreateAsync(AccountInputDto inputDto)
        {
            if (await _repository.ExistsAccountAsync(inputDto.Account))
            {
                throw new BusiException("登录帐号已存在");
            }
            var model = inputDto.MapTo <TAccount>();

            model.Id           = IdentityHelper.Guid32;
            model.PasswordSalt = IdentityHelper.Guid16;
            model.Password     = $"{model.Password},{model.PasswordSalt}".Md5();
            model.CreateTime   = Clock.Now;
            var result = await _repository.InsertAsync(model);

            if (result <= 0)
            {
                throw new BusiException("创建账户失败");
            }
            return(model.MapTo <AccountDto>());
        }
Exemplo n.º 10
0
        public async Task UpdateNonEditableAccount()
        {
            var accounts = await GetAccounts();

            var lastAccount = accounts.Item1.FirstOrDefault(x => x.CanEdited == false);

            var payload = new AccountInputDto
            {
                Description = lastAccount?.Description + " Updated",
                Type        = lastAccount?.TypeId,
                Tags        = new List <AccountTagInputDto>()
            };

            var account = Utils.PutWebApi("FinanceWebApi", $"{AccountsUrl}/{lastAccount?.AccountId}", payload);

            Task.WaitAll(account);

            var response = JsonConvert.DeserializeObject <Response>(account.Result);

            Assert.IsTrue(response.isSuccessful == false, "Account not Updated");
        }
 public object UpdateAccount(int id, AccountInputDto account)
 {
     return(!ModelState.IsValid || account == null
         ? BadRequest(ModelState)
         : controller.UpdateAccount(id, account));
 }
Exemplo n.º 12
0
        public object CreateAccount(AccountInputDto account)
        {
            SqlHelper sqlHelper = new SqlHelper(connectionString);
            try
            {
                sqlHelper.VerifyConnection();
                sqlHelper.SqlBeginTransaction();

                var accountName = GetAccountName(account.Tags, account.Type);
                List<SqlParameter> accountParameters = new List<SqlParameter>
                {
                    new SqlParameter("name", accountName), new SqlParameter("description", account.Description),
                    new SqlParameter("type", account.Type)
                };

                var accountQuery = $@"INSERT INTO [account]
                        ([name]
                        ,[description]
                        ,[account_type_id])
                        VALUES
                        (@name
                        ,@description
                        ,@type)
                        SELECT SCOPE_IDENTITY() AS 'Identity'";

                sqlHelper.Insert(accountQuery, CommandType.Text, accountParameters.ToArray(), out int accountId);

                if (account.Tags.Count > 0)
                {
                    foreach (var accountTag in account.Tags)
                    {
                        List<SqlParameter> tagParameters = new List<SqlParameter>
                        {
                            new SqlParameter("accountId", accountId), new SqlParameter("tagId", accountTag.Id),
                            new SqlParameter("tagValue", accountTag.Value)
                        };

                        var tagQuery = $@"INSERT INTO [account_tag]
                                ([account_id]
                                ,[tag_id]
                                ,[tag_value])
                                VALUES
                                (@accountId
                                ,@tagId
                                ,@tagValue)";

                        sqlHelper.Insert(tagQuery, CommandType.Text, tagParameters.ToArray());
                    }
                }

                sqlHelper.SqlCommitTransaction();
                sqlHelper.CloseConnection();
            }
            catch (Exception ex)
            {
                sqlHelper.SqlRollbackTransaction();
                sqlHelper.CloseConnection();
                Console.WriteLine($"SQL Rollback Transaction Exception: {ex}");
                return Utils.Wrap(false);
            }

            return Utils.Wrap(true);
        }
Exemplo n.º 13
0
        public object UpdateAccount(int id, AccountInputDto account)
        {
            SqlHelper sqlHelper = new SqlHelper(connectionString);

            if (AccountHasJournal(id))
            {
                return Utils.Wrap(false, null, HttpStatusCode.OK, "An Account having Journal cannot be Edited");
            }

            try
            {
                sqlHelper.VerifyConnection();
                sqlHelper.SqlBeginTransaction();

                var accountName = GetAccountName(account.Tags, account.Type);
                List<SqlParameter> accountParameters = new List<SqlParameter>
                {
                    new SqlParameter("id", id), new SqlParameter("name", accountName),
                    new SqlParameter("description", account.Description),
                    new SqlParameter("type", account.Type)
                };

                List<SqlParameter> tagDeleteParameters = new List<SqlParameter>
                {
                    new SqlParameter("id", id)
                };

                var accountQuery = $@"UPDATE [account]
                                    SET [name] = @name
                                    ,[description] = @description
                                    ,[account_type_id] = @type
                                    WHERE [id] = @id";

                var tagDeleteQuery = $@"DELETE FROM [account_tag]
                                    WHERE [account_tag].[account_id] = @id";

                sqlHelper.Update(accountQuery, CommandType.Text, accountParameters.ToArray());
                sqlHelper.Delete(tagDeleteQuery, CommandType.Text, tagDeleteParameters.ToArray());

                if (account.Tags.Count > 0)
                {
                    foreach (var accountTag in account.Tags)
                    {
                        List<SqlParameter> tagParameters = new List<SqlParameter>
                        {
                            new SqlParameter("accountId", id), new SqlParameter("tagId", accountTag.Id),
                            new SqlParameter("tagValue", accountTag.Value)
                        };

                        var tagQuery = $@"INSERT INTO [account_tag]
                                ([account_id]
                                ,[tag_id]
                                ,[tag_value])
                                VALUES
                                (@accountId
                                ,@tagId
                                ,@tagValue)";

                        sqlHelper.Insert(tagQuery, CommandType.Text, tagParameters.ToArray());
                    }
                }

                sqlHelper.SqlCommitTransaction();
                sqlHelper.CloseConnection();
            }
            catch (Exception ex)
            {
                sqlHelper.SqlRollbackTransaction();
                sqlHelper.CloseConnection();
                Console.WriteLine($"SQL Rollback Transaction Exception: {ex}");
                return Utils.Wrap(false);
            }

            return Utils.Wrap(true);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 用户修改密码
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task <IActionResult> SaveAccountPWD(AccountInputDto data)
        {
            bool result = await _service.SaveAccountPWD(data);

            return(Json(new { code = result, msg = result ? "修改成功" : "修改失败" }));
        }
Exemplo n.º 15
0
        /// <summary>
        /// 验证用户信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task <IActionResult> UserVilidata(AccountInputDto data)
        {
            bool result = await _service.UserVilidata(data);

            return(Json(new { code = result, msg = result ? "验证成功" : "验证失败" }));
        }
Exemplo n.º 16
0
 public object UpdateAccount(int id, AccountInputDto account)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 17
0
 public object CreateAccount(AccountInputDto account)
 {
     throw new System.NotImplementedException();
 }
 public object CreateAccount(AccountInputDto account)
 {
     return(!ModelState.IsValid || account == null
         ? BadRequest(ModelState)
         : controller.CreateAccount(account));
 }