/// <summary>
        /// Determines whether the specified size exists on the measure
        /// </summary>
        /// <param name="sizes">The sizes to check.</param>
        /// <returns>
        ///   <c>true</c> if the specified sizes exists on the measure; otherwise, <c>false</c>.
        /// </returns>
        public Boolean HasSize(params KeyValuePair <string, double>[] sizes)
        {
            Boolean flag = true;

            for (int i = 0; i < sizes.Length && flag; i++)
            {
                flag = flag && (Sizes.FirstOrDefault(x => x.Measure == sizes[i].Key && x.Nominal == sizes[i].Value).Measure != null);
            }
            return(flag);
        }
        public List <MessageString> Validate(IUnitOfWork db,
                                             ILogService log,
                                             DateTime when)
        {
            var messages = new List <MessageString>();

            if (IncomeType == (int)BoxIncomePackType.PPK)
            {
                var existBoxes = db.SealedBoxes.GetAllAsDto().Where(b => b.StyleId == StyleId &&
                                                                    b.BoxQuantity == BoxQuantity)
                                 .ToList();

                foreach (var existBox in existBoxes)
                {
                    var boxItems = db.SealedBoxItems.GetByBoxIdAsDto(existBox.Id);
                    var isEqual  = Sizes.Count(s => s.Breakdown > 0) == boxItems.Count;
                    foreach (var boxItem in boxItems)
                    {
                        var size = Sizes.FirstOrDefault(s => s.Id == boxItem.StyleItemId);
                        if (size == null || size.Breakdown != boxItem.BreakDown)
                        {
                            isEqual = false;
                        }
                    }

                    if (isEqual)
                    {
                        messages.Add(new MessageString()
                        {
                            Message = "A similar boxes already exist (created on " + DateHelper.ToDateString(existBox.CreateDate) + "). Are you sure you would like to create them?",
                            Status  = MessageStatus.Info,
                        });

                        return(messages);
                    }
                }
            }

            if (IncomeType == (int)BoxIncomePackType.PolyBagged)
            {
                foreach (var size in Sizes.Where(si => si.Quantity > 0))
                {
                    var totalQuantity = UnitsPerBox * size.Quantity;

                    var existBoxes = db.SealedBoxes.GetAllAsDto().Where(b => b.StyleId == StyleId &&
                                                                        b.BoxQuantity == size.Quantity)
                                     .ToList();

                    foreach (var existBox in existBoxes)
                    {
                        var boxItems           = db.SealedBoxItems.GetByBoxIdAsDto(existBox.Id);
                        var existTotalQuantity = boxItems.Sum(bi => bi.BreakDown) * existBox.BoxQuantity;
                        if (existTotalQuantity == totalQuantity && boxItems.Count == 1)
                        {
                            messages.Add(new MessageString()
                            {
                                Message = "A similar boxes already exist (created on " + DateHelper.ToDateString(existBox.CreateDate) + "). Are you sure you would like to create them?",
                                Status  = MessageStatus.Info,
                            });

                            return(messages);
                        }
                    }
                }
            }

            if (IncomeType == (int)BoxIncomePackType.Other)
            {
                var existBoxes = db.OpenBoxes.GetAllAsDto().Where(b => b.StyleId == StyleId &&
                                                                  b.BoxQuantity == 1)
                                 .ToList();

                foreach (var existBox in existBoxes)
                {
                    var boxItems = db.OpenBoxItems.GetByBoxIdAsDto(existBox.Id);

                    var isEqual = Sizes.Count(s => s.Quantity > 0) == boxItems.Count;
                    foreach (var boxItem in boxItems)
                    {
                        var size = Sizes.FirstOrDefault(s => s.Id == boxItem.StyleItemId);
                        if (size == null || size.Quantity != boxItem.Quantity)
                        {
                            isEqual = false;
                        }
                    }

                    if (isEqual)
                    {
                        messages.Add(new MessageString()
                        {
                            Message = "A similar box already exists (created on " +
                                      DateHelper.ToDateString(existBox.CreateDate) + "). Are you sure you would like to create one?",
                            Status = MessageStatus.Info,
                        });

                        return(messages);
                    }
                }
            }

            return(messages);
        }
 /// <summary>
 /// Gets the <see cref="RivieraSize"/> with the specified key.
 /// </summary>
 /// <value>
 /// The <see cref="RivieraSize"/>.
 /// </value>
 /// <param name="key">The key.</param>
 /// <returns>The Riviera size associated to a key</returns>
 public RivieraSize this[String key] => Sizes.FirstOrDefault(x => x.Measure == key);