public async Task Update(Duck duck)
        {
            if (!Repository.Ducks.ContainsKey(duck.Name))
            {
                throw new ArgumentException("Duck doesn't exists");
            }

            Repository.Ducks[duck.Name] = duck;
        }
        //[AuthorizationFilter]
        public async Task<HttpResponseMessage> Create(Duck duck)
        {
            if (Repository.Ducks.ContainsKey(duck.Name))
            {
                Repository.Ducks[duck.Name] = duck;
                return Request.CreateResponse(HttpStatusCode.Created);
            }

            Repository.Ducks.Add(duck.Name, duck);

            return Request.CreateResponse(HttpStatusCode.Created);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var quack    = new Duck("Sir Quackalot", "Mallard", 100, 17);
            var quacker  = new Duck("Quackers", "Eider", 100, 12);
            var quackers = new Duck("Orange", "Mallard", 101, 17);

            if (quack.Equals(quackers))//weight comparer
            {
                Console.WriteLine("a match!");
                Console.ReadLine();
            }

            else
            {
                Console.WriteLine("no match!");
                Console.ReadLine();
            }
        }
        public async Task<IEnumerable<Duck>> Hatch(string id)
        {
            if (!Repository.Ducks.ContainsKey(id))
            {
                throw new ArgumentException("Duck doesn't exists");
            }

            var duck = Repository.Ducks[id];
            var children = new List<Duck>();
            for (var i = 0; i < duck.EggsCount; i++)
            {
                var child = new Duck()
                {
                    Name = duck.Name + i,
                    Color = duck.Color
                };
                children.Add(child);
                Repository.Ducks.Add(child.Name, child);
            }

            return children;
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            List <Duck> ducks = new List <Duck>()
            {
                new Duck()
                {
                    Kind = KindOfDuck.Mallard, Size = 17
                },
                new Duck()
                {
                    Kind = KindOfDuck.Muscovy, Size = 18
                },
                new Duck()
                {
                    Kind = KindOfDuck.Decoy, Size = 14
                },
                new Duck()
                {
                    Kind = KindOfDuck.Muscovy, Size = 11
                },
                new Duck()
                {
                    Kind = KindOfDuck.Mallard, Size = 14
                },
                new Duck()
                {
                    Kind = KindOfDuck.Decoy, Size = 13
                },
            };

            Console.WriteLine("--Original duck list");
            PrintDucks(ducks);

            //IComparable sort
            Console.WriteLine("\r\n--IComparable Sort -  size descending");
            ducks.Sort();
            PrintDucks(ducks);

            //IComparer sort
            Console.WriteLine("\r\n--IComparer Sort - size ascending");
            DuckCompareBySize sizeComparer = new DuckCompareBySize();

            ducks.Sort(sizeComparer);
            PrintDucks(ducks);

            Console.WriteLine("\r\n--IComparer Sort - Kind ascending by enum index");
            DuckCompareByKind kindComparer = new DuckCompareByKind();

            ducks.Sort(kindComparer);
            PrintDucks(ducks);

            Console.WriteLine("\r\n--IComparer Complex Sort - Size/Kind ascending ");
            DuckComparer comparer = new DuckComparer();

            comparer.SortBy = SortCriteria.SizeThenKind;
            ducks.Sort(comparer);
            PrintDucks(ducks);

            Console.WriteLine("\r\n--IComparer Complex Sort - Kind/Size ascending ");
            //DuckComparer comparer = new DuckComparer();
            comparer.SortBy = SortCriteria.KindThenSize;
            ducks.Sort(comparer);
            PrintDucks(ducks);

            //IEnumerator
            Duck[] duckArray = new Duck[6];
            duckArray.GetEnumerator();

            Console.WriteLine("\r\n--IEnumerator loop ");

            IEnumerator <Duck> enumerator = ducks.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Duck duck = enumerator.Current;
                Console.WriteLine(duck);
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            // Instantiate a new Mallard Duck
            Mallard liveDuck = new Mallard();
            {
                liveDuck.floats = true;
                liveDuck.flies  = true;
                liveDuck.quacks = true;
                liveDuck.legs   = 2;
                liveDuck.eyes   = 2;
                liveDuck.madeOf = "meat";
            }

            // Instantiate a new Wooden Duck
            Wooden woodDuck = new Wooden();
            {
                woodDuck.floats = true;
                woodDuck.flies  = false;
                woodDuck.quacks = false;
                woodDuck.legs   = 0;
                woodDuck.eyes   = 0;
                woodDuck.madeOf = "wood";
            }


            // Instantiate a new Rubber Duck
            Rubber rubberDucky = new Rubber();
            {
                rubberDucky.floats = true;
                rubberDucky.flies  = false;
                rubberDucky.quacks = false;
                rubberDucky.legs   = 0;
                rubberDucky.eyes   = 0;
                rubberDucky.name   = "George";
                rubberDucky.madeOf = "rubber";
                rubberDucky.color  = "yellow";
            }

            // Instantiate a new Rubber Duck with a custom color
            Rubber redRubberDucky = new Rubber();
            {
                redRubberDucky.color = "red";
            }

            // You cant instantiate the class Duck because it is an abstract class.
            Duck newDuck = new Duck();

            // Add one of each of the ducks to a List
            var ducks = new List <Duck>();

            ducks.Add(liveDuck);
            ducks.Add(woodDuck);
            ducks.Add(rubberDucky);
            ducks.Add(redRubberDucky);

            // Remove one of the ducks from the List
            ducks.Remove(woodDuck);

            // Iterate through the list
            foreach (var d in ducks)
            {
                bool DoesFloat;
                if (d.floats == true)
                {
                    DoesFloat = true;
                    Console.WriteLine("This Duck Floats!");
                    Console.ReadLine();
                }
                Console.WriteLine("This Duck sinks!");
                Console.ReadLine();
            }

            // What about the eyes? How would you implement giving the ducks eyes?
        }
Beispiel #7
0
 static void Info(Duck duck)
 {
     duck.Fly();
     duck.Quick();
     duck.Composition();
 }