コード例 #1
0
        public async Task <IActionResult> PatchTodoItem(long id, [FromBody] JsonPatchDocument <FlowDto> patchItem)
        {
            var flow = await _context.Flows.FindAsync(id);

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

            FlowDto flowDto = _mapper.Map <FlowDto>(flow);

            patchItem.ApplyTo(flowDto);
            _mapper.Map(flowDto, flow);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!FlowExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> UpdateFlow(long id, FlowDto flowDTO)
        {
            if (id != flowDTO.Id)
            {
                return(BadRequest());
            }

            var flow = await _context.Flows.FindAsync(id);

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

            flow.Name       = flowDTO.Name;
            flow.Pos        = flowDTO.Pos;
            flow.CategoryId = flowDTO.CategoryId;
            flow.UpdatedAt  = DateTime.Now;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!FlowExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
コード例 #3
0
        public FlowDto Add(FlowDto entity)
        {
            entity.Id = Guid.NewGuid();
            _repository.Add(new Flow
            {
                Id    = entity.Id,
                Title = entity.Title
            });

            return(entity);
        }
コード例 #4
0
        public bool Update(Guid id, FlowDto entity)
        {
            var flow = _repository.Get().FirstOrDefault(x => x.Id == id);

            if (flow == null)
            {
                return(false);
            }

            flow.Title = entity.Title;
            _repository.Update(flow);

            return(true);
        }
コード例 #5
0
        public async Task <ActionResult <Flow> > CreateFlow(FlowDto flowDTO)
        {
            var flow = new Flow
            {
                Name       = flowDTO.Name,
                CategoryId = flowDTO.CategoryId,
                Pos        = flowDTO.Pos,
                CreatedAt  = DateTime.Now,
                UpdatedAt  = DateTime.Now
            };

            _context.Flows.Add(flow);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetFlow), new { id = flow.Id }, FlowToDTO(flow)));
        }
コード例 #6
0
        public void FlowService_Add_Returns_ParamaterItself()
        {
            // Arrange
            var service  = new FlowService(mockFlowRepo.Object);
            var flowData = new FlowDto
            {
                Id    = Guid.NewGuid(),
                Title = "Test Flow"
            };

            // Act
            var flow = service.Add(flowData);

            // Assert
            Assert.IsNotNull(flow);
            Assert.AreEqual(flowData.Id, flow.Id);
            Assert.AreEqual(flowData.Title, flow.Title);
        }
コード例 #7
0
        public async Task <Flow> UpdateAsync(Guid id, FlowDto dto)
        {
            var flow = await GetAsync(id);

            var lendee = await _context.Participants.FirstOrDefaultAsync(c => c.Id == dto.LendeeId);

            var lender = await _context.Participants.FirstOrDefaultAsync(c => c.Id == dto.LenderId);

            var currency = await _context.Currencies.FirstOrDefaultAsync(c => c.Code == dto.CurrencyCode);

            flow.Lendee  = lendee;
            flow.Lender  = lender;
            flow.Comment = dto.Comment;
            flow.Amount  = new Money {
                Currency = currency,
                Value    = dto.Amount
            };
            await _context.SaveChangesAsync();

            return(flow);
        }
コード例 #8
0
        public async Task Add_ShouldAddFlow()
        {
            // Arrange
            var         options = BuildContextOptions();
            Currency    currency;
            Participant lender;
            Participant lendee;

            using (var context = new BorrowBuddyContext(options)) {
                currency = context.AddCurrency();
                lender   = context.AddParticipant();
                lendee   = context.AddParticipant();
                context.SaveChanges();
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Act
                var service = new FlowService(context);
                var dto     = new FlowDto {
                    LendeeId     = lendee.Id,
                    LenderId     = lender.Id,
                    Amount       = 100,
                    CurrencyCode = currency.Code
                };
                await service.AddAsync(dto);
            }

            // Assert
            using (var context = new BorrowBuddyContext(options)) {
                var flow = context.Flows.FirstOrDefault();
                Assert.NotNull(flow);
                Assert.Equal(lender.Id, flow.Lender.Id);
                Assert.Equal(lendee.Id, flow.Lendee.Id);
                Assert.Equal(100, flow.Amount.Value);
                Assert.Equal(currency.Code, flow.Amount.Currency.Code);
            }
        }
コード例 #9
0
        public async Task <Flow> AddAsync(FlowDto dto)
        {
            var lendee = await _context.Participants.FirstOrDefaultAsync(c => c.Id == dto.LendeeId);

            var lender = await _context.Participants.FirstOrDefaultAsync(c => c.Id == dto.LenderId);

            var currency = await _context.Currencies.FirstOrDefaultAsync(c => c.Code == dto.CurrencyCode);

            var flow = new Flow {
                Lendee    = lendee,
                Lender    = lender,
                Comment   = dto.Comment,
                Timestamp = DateTimeOffset.UtcNow,
                Amount    = new Money {
                    Currency = currency,
                    Value    = dto.Amount
                }
            };

            _context.Flows.Add(flow);
            await _context.SaveChangesAsync();

            return(flow);
        }