private RoomAllocationRequirement Create(Models.Requests.AllocationRequirement requirement)
 => new RoomAllocationRequirement
 {
     RoomId              = requirement.RoomId,
     SeasonRangeId       = requirement.SeasonRangeId,
     ReleaseDays         = requirement.ReleaseDays,
     Allotment           = requirement.Allotment,
     MinimumLengthOfStay = requirement.MinimumLengthOfStay
 };
        public Task <Result <Models.Responses.AllocationRequirement> > Modify(int contractId, int allocationRequirementId, Models.Requests.AllocationRequirement allocationRequirementRequest)
        {
            return(ValidationHelper.Validate(allocationRequirementRequest, new AllocationRequirementsValidator())
                   .Bind(() => _managerContext.GetServiceSupplier())
                   .Check(serviceSupplier => _serviceSupplierContext.EnsureContractBelongsToServiceSupplier(serviceSupplier, contractId))
                   .Bind(_ => Update()));


            Task <Result <Models.Responses.AllocationRequirement> > Update()
            {
                return(GetAllocationRequirement().Bind(UpdateDbEntry).Bind(UpdateDb).Map(Build));


                async Task <Result <RoomAllocationRequirement> > GetAllocationRequirement()
                {
                    var allocationRequirement = await _dbContext.RoomAllocationRequirements.Include(ar => ar.SeasonRange)
                                                .ThenInclude(sr => sr.Season)
                                                .SingleOrDefaultAsync(ar => ar.Id == allocationRequirementId && ar.SeasonRange.Season.ContractId == contractId);

                    return(allocationRequirement is null
                        ? Result.Failure <RoomAllocationRequirement>("Failed to retrieve the allocation requirement")
                        : Result.Success(allocationRequirement));
                }

                Result <RoomAllocationRequirement> UpdateDbEntry(RoomAllocationRequirement allocationRequirement)
                {
                    allocationRequirement.RoomId              = allocationRequirementRequest.RoomId;
                    allocationRequirement.SeasonRangeId       = allocationRequirementRequest.SeasonRangeId;
                    allocationRequirement.ReleaseDays         = allocationRequirementRequest.ReleaseDays;
                    allocationRequirement.Allotment           = allocationRequirementRequest.Allotment;
                    allocationRequirement.MinimumLengthOfStay = allocationRequirementRequest.MinimumLengthOfStay;

                    return(allocationRequirement);
                }

                async Task <Result <RoomAllocationRequirement> > UpdateDb(RoomAllocationRequirement allocationRequirement)
                {
                    var entry = _dbContext.RoomAllocationRequirements.Update(allocationRequirement);
                    await _dbContext.SaveChangesAsync();

                    return(entry.Entity);
                }
            }
        }