コード例 #1
0
 public void Given_I_have_made_valid_changes_to_an_existing_ToDo()
 {
     _existingItem = new MasterTradingAgreementBuilder().Persist();
     _request      = _existingItem
                     .Adapt <UpdateMasterTradingAgreementRequest>()
                     .With(x => x.Comments  = UpdatedValue);
     _request.ContractSchedules[0].Comments = UpdatedValue;
 }
コード例 #2
0
        public void Given_I_have_made_invalid_changes_to_an_existing_item()
        {
            _existingItem = new MasterTradingAgreementBuilder().Persist();

            _request = _existingItem
                       .Adapt <UpdateMasterTradingAgreementRequest>()
                       .With(x => x.Id       = _existingItem.Id)
                       .With(x => x.Name     = string.Empty)
                       .With(x => x.Comments = "Updated");
        }
コード例 #3
0
        public async Task <Result> Handle(CreateMasterTradingAgreementCommand request, CancellationToken cancellationToken)
        {
            var counterparty = _staticData.Companies[request.CounterpartyId];

            if (counterparty is null)
            {
                return(ResultFactory.RecordNotFound("Company", request.CounterpartyId));
            }

            _db.Attach(counterparty).State = EntityState.Unchanged;

            var type     = (MasterTradingAgreementType)request.Type;
            var duration = new DateRange(request.DurationStartDate, request.DurationEndDate);
            var entity   = new MasterTradingAgreement(request.Name, type, duration, counterparty, request.Comments);

            foreach (var dto in request.ContractSchedules)
            {
                var location = _staticData.Locations[dto.LocationId];
                if (location is null)
                {
                    return(ResultFactory.RecordNotFound("Location", dto.LocationId));
                }
                _db.Attach(location).State = EntityState.Unchanged;

                var scheduleType     = (ContractScheduleType)request.Type;
                var scheduleDuration = new DateRange(request.DurationStartDate, request.DurationEndDate);
                var schedule         = new ContractSchedule(dto.Name, scheduleType, scheduleDuration,
                                                            dto.Comments, entity, location);
                entity.AddContractSchedule(schedule);
            }

            _db.MasterTradingAgreements.Add(entity);

            await _db.SaveChangesAsync(cancellationToken);

            return(Result.Ok()
                   .WithReason(new RecordsCreatedSuccess(entity.Id)));
        }
コード例 #4
0
 public void Given_I_have_an_existing_MasterTradingAgreement()
 {
     _existingItem = new MasterTradingAgreementBuilder().Persist();
 }