Ejemplo n.º 1
0
        /// <summary>
        /// Converts domain object to DTO.
        /// </summary>
        /// <param name="setColour">The set colour.</param>
        /// <returns>Set Colour.</returns>
        public static SetColourDto ToDto(ISetColour setColour)
        {
            if (setColour == null)
            {
                throw new ArgumentNullException(nameof(setColour));
            }

            return(new SetColourDto(
                       id: setColour.Id,
                       code: setColour.Code,
                       name: setColour.Name));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public void CreateSetColour(ISetColour setColour)
        {
            SetColourDto setColourDto = SetColourDto.ToDto(setColour);

            this.Context.SetColours.Add(setColourDto);
            int count = this.Context.SaveChanges();

            if (count != 1)
            {
                throw new ApplicationException($"Unexpectedly created {count} rows");
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public ISetWithPacks Create32BoardSet(
            string ownerCode,
            string setPurposeCode,
            string setColourCode,
            string description)
        {
            if (ownerCode == null)
            {
                throw new ArgumentNullException(nameof(ownerCode));
            }

            if (setPurposeCode == null)
            {
                throw new ArgumentNullException(nameof(setPurposeCode));
            }

            if (setColourCode == null)
            {
                throw new ArgumentNullException(nameof(setColourCode));
            }

            IOwner      owner      = this.GetOwner(ownerCode);
            ISetPurpose setPurpose = this.GetSetPurpose(setPurposeCode);
            ISetColour  setColour  = this.GetSetColour(setColourCode);

            ISet set = new Set(
                id: Guid.NewGuid(),
                lowBoardNumber: 1,
                highBoardNumber: 32,
                description: description,
                owner: owner,
                setPurpose: setPurpose,
                setColour: setColour);

            IList <IPack> packs = new List <IPack>();

            for (int boardNumber = set.LowBoardNumber; boardNumber <= set.HighBoardNumber; boardNumber++)
            {
                IPack pack = new Pack(
                    id: Guid.NewGuid(),
                    packColour: boardNumber % 2 == 1 ? this.RedPackColour : this.BluePackColour,
                    set: set,
                    enteredService: DateTime.Today,
                    boardNumber: boardNumber);
                packs.Add(pack);
            }

            return(new SetWithPacks(set, packs));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Set"/> class.
        /// </summary>
        /// <param name="id">Set Id.</param>
        /// <param name="lowBoardNumber">Low Board Number.</param>
        /// <param name="highBoardNumber">High Board Number.</param>
        /// <param name="description">Description.</param>
        /// <param name="owner">Owner.</param>
        /// <param name="setPurpose">Set Purpose.</param>
        /// <param name="setColour">Set Colour.</param>
        public Set(
            Guid id,
            int lowBoardNumber,
            int highBoardNumber,
            string description,
            IOwner owner,
            ISetPurpose setPurpose,
            ISetColour setColour)
        {
            if (lowBoardNumber < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(lowBoardNumber),
                          ExceptionResource.LowBoardNumberShouldBeAtLeastOne);
            }

            if (lowBoardNumber > highBoardNumber)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(lowBoardNumber),
                          ExceptionResource.LowBoardNumberShouldNotBeHigherThanHighBoardNumber);
            }

            if (string.IsNullOrWhiteSpace(description))
            {
                throw new ArgumentNullException(nameof(description));
            }

            this.Id              = id;
            this.LowBoardNumber  = lowBoardNumber;
            this.HighBoardNumber = highBoardNumber;
            this.Description     = description;
            this.Owner           = owner ?? throw new ArgumentNullException(nameof(owner));
            this.SetPurpose      = setPurpose ?? throw new ArgumentNullException(nameof(setPurpose));
            this.SetColour       = setColour ?? throw new ArgumentNullException(nameof(setColour));
        }