Пример #1
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateSettlementDto request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            await _settlementService.CreateAsync(request);

            return(ApiResponseOk());
        }
        public async Task CreateAsync([FromBody] SettlementRequestModel model, string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                throw new ValidationApiException(HttpStatusCode.BadRequest, "User id required");
            }

            try
            {
                await _settlementService.CreateAsync(model.IndexName, model.Amount, model.Comment, model.WalletId,
                                                     model.ClientId, userId, model.IsDirect);
            }
            catch (InvalidOperationException exception)
            {
                throw new ValidationApiException(HttpStatusCode.BadRequest, exception.Message);
            }
        }
Пример #3
0
 public async Task HandleAsync(CreateSettlement command)
 {
     command.SettlementId = Guid.NewGuid();
     await _settlementService.CreateAsync(command.SettlementId, command.CurrentUserId,
                                          command.Name, command.Description, command.SettleType);
 }
Пример #4
0
        public async Task SeedAsync()
        {
            var users = await _userService.BrowseAsync();

            if (users.Any())
            {
                return;
            }

            // var tasks = new List<Task>();
            // var user1Guid = Guid.Parse("00000000-0000-0000-0000-000000000001");
            // var user2Guid = Guid.Parse("00000000-0000-0000-0000-000000000002");
            // var user3Guid = Guid.Parse("00000000-0000-0000-0000-000000000003");
            // var settlement1Guid = Guid.Parse("00000000-0000-0000-0000-000000000010");
            // var settlement2Guid = Guid.Parse("00000000-0000-0000-0000-000000000020");
            // await _userService.RegisterAsync(user1Guid, "*****@*****.**",
            //     "user1", "secret");
            // await _userService.RegisterAsync(user2Guid, "*****@*****.**",
            //     "user2", "secret", "admin");
            // await _userService.RegisterAsync(user3Guid, "*****@*****.**",
            //     "user3", "secret");

            // await _settlementService.CreateAsync(settlement1Guid, user1Guid,
            //     "Settlement1");
            // await _settlementService.CreateAsync(settlement2Guid, user1Guid,
            //     "Settlement1");

            // await _expenseService.CreateAsync(settlement1Guid, user1Guid,
            //     "Expense1Name", 10m);
            // await _expenseService.CreateAsync(settlement1Guid, user2Guid,
            //     "Expense2Name", 500m);
            // await _expenseService.CreateAsync(settlement1Guid, user2Guid,
            //     "Expense2Name", 600m);
            // await _expenseService.CreateAsync(settlement1Guid, user2Guid,
            //     "Expense3Name", 30m);
            // await _expenseService.CreateAsync(settlement1Guid, user2Guid,
            //     "Expense4Name", 40m);
            // await _expenseService.CreateAsync(settlement1Guid, user3Guid,
            //     "Expense5Name", 500m);

            var tasks           = new List <Task>();
            var user1Guid       = Guid.Parse("00000000-0000-0000-0000-000000000001");
            var user2Guid       = Guid.Parse("00000000-0000-0000-0000-000000000002");
            var user3Guid       = Guid.Parse("00000000-0000-0000-0000-000000000003");
            var settlement1Guid = Guid.Parse("00000000-0000-0000-0000-000000000010");
            var settlement2Guid = Guid.Parse("00000000-0000-0000-0000-000000000020");

            tasks.Add(_userService.RegisterAsync(user1Guid, "*****@*****.**",
                                                 "user1", "secret"));
            tasks.Add(_userService.RegisterAsync(user2Guid, "*****@*****.**",
                                                 "user2", "secret", "admin"));
            tasks.Add(_userService.RegisterAsync(user3Guid, "*****@*****.**",
                                                 "user3", "secret"));

            tasks.Add(_settlementService.CreateAsync(settlement1Guid, user1Guid,
                                                     "Settlement1"));
            tasks.Add(_settlementService.CreateAsync(settlement2Guid, user1Guid,
                                                     "Settlement1"));

            tasks.Add(_expenseService.CreateAsync(settlement1Guid, user1Guid,
                                                  "Expense1Name", 10m));
            tasks.Add(_expenseService.CreateAsync(settlement1Guid, user2Guid,
                                                  "Expense2Name", 500m));
            tasks.Add(_expenseService.CreateAsync(settlement1Guid, user2Guid,
                                                  "Expense2Name", 600m));
            tasks.Add(_expenseService.CreateAsync(settlement1Guid, user2Guid,
                                                  "Expense3Name", 30m));
            tasks.Add(_expenseService.CreateAsync(settlement1Guid, user2Guid,
                                                  "Expense4Name", 40m));
            tasks.Add(_expenseService.CreateAsync(settlement1Guid, user3Guid,
                                                  "Expense5Name", 500m));

            await Task.WhenAll(tasks);
        }