Ejemplo n.º 1
0
 public static DestinationOption ToDestinationOption(this string key, DestinationOption defaultValue = DestinationOption.mg, bool raiseException = false)
 {
     if (Enum.TryParse(key, true, out DestinationOption value))
     {
         return(value);
     }
     else
     {
         return(raiseException ? throw new ArgumentException($"{key} is not DestinationOption value.") : defaultValue);
     }
 }
Ejemplo n.º 2
0
        public string[] GetRandomNumbersFor(string number, DestinationOption destinationOption, int amount)
        {
            using (var context = new CellularDbContext())
            {
                string[] result;
                switch (destinationOption)
                {
                case DestinationOption.Friends:
                    var pack = context.Packages.FirstOrDefault(p => p.LineNumber == number);

                    if (pack != null && pack.IncludesFriends)
                    {
                        result = new string[] { pack.Number1, pack.Number2, pack.Number3 };
                        break;
                    }
                    else
                    {
                        return(new string[0]);
                    }
                //throw new InvalidOperationException("The given line does not have a package or its does not includ friends. ");

                case DestinationOption.All:
                    result = context.Lines
                             .Where(l => l.PhoneNumber != number)
                             .OrderBy(l => Guid.NewGuid())
                             .Take(amount)
                             .Select(l => l.PhoneNumber)
                             .ToArray();

                    break;

                default: throw new NotSupportedException();
                }
                CompleteToAmount(ref result, amount);
                return(result);
            }
        }