//[EnableQuery]
        //public IHttpActionResult GetWindow([FromODataUri] int key)
        //{
        //    return Ok(_windows.Single(w => w.Id == key));
        //}

        public IHttpActionResult Post(Window window)
        {
            _windows.Add(window);
            window.Id = _windows.Count + 1;
            Rectangle rectangle = window.CurrentShape as Rectangle;
            if(rectangle!=null)
            {
                rectangle.Fill();
            }
            window.OptionalShapes.OfType<Rectangle>().ToList().ForEach(r => r.Fill());
            return Created(window);
        }
        public WindowsController()
        {
            Polygon triagle = new Polygon() { HasBorder = true, Vertexes = new List<Point>() };
            triagle.Vertexes.Add(new Point() { X = 1, Y = 2 });
            triagle.Vertexes.Add(new Point() { X = 2, Y = 3 });
            triagle.Vertexes.Add(new Point() { X = 4, Y = 8 });

            Rectangle rectangle = new Rectangle(topLeft: new Point(), width: 2, height: 2);
            Circle circle = new Circle() { HasBorder = true, Center = new Point(), Radius = 2 };

            Window dashboardWindow = new Window
            {
                Id = 1,
                Name = "CircleWindow",
                CurrentShape = circle,
                OptionalShapes = new List<Shape>(),
            };
            dashboardWindow.OptionalShapes.Add(rectangle);
            _windows.Add(dashboardWindow);

            Window popupWindow = new Window
            {
                Id = 2,
                Name = "Popup",
                CurrentShape = rectangle,
                OptionalShapes = new List<Shape>(),
                Parent = dashboardWindow,
            };

            popupWindow.OptionalShapes.Add(triagle);
            popupWindow.OptionalShapes.Add(circle);
            _windows.Add(popupWindow);

            Window anotherPopupWindow = new Window
            {
                Id = 3,
                Name = "AnotherPopup",
                CurrentShape = rectangle,
                OptionalShapes = new List<Shape>(),
                Parent = popupWindow,
            };

            anotherPopupWindow.OptionalShapes.Add(triagle);
            anotherPopupWindow.OptionalShapes.Add(circle);
            _windows.Add(anotherPopupWindow);
        }
        public IHttpActionResult Patch(int key, Delta<Window> delta)
        {
            delta.TrySetPropertyValue("Id", key); // It is the key property, and should not be updated.

            Window window = _windows.FirstOrDefault(e => e.Id == key);
            if (window == null)
            {
                window = new Window();
                delta.Patch(window);
                return Created(window);
            }

            delta.Patch(window);
            return Ok(window);
        }
        public IHttpActionResult Put(int key, Window window)
        {
            if (key != window.Id)
            {
                return BadRequest();
            }
            Rectangle rectangle = window.CurrentShape as Rectangle;
            if (rectangle != null)
            {
                rectangle.Fill();
            }
            window.OptionalShapes.OfType<Rectangle>().ToList().ForEach(r => r.Fill());

            Window originalWindow = _windows.FirstOrDefault(e => e.Id == key);
            if (window == null)
            {
                _windows.Add(window);
                return Created(window);
            }

            _windows.Remove(originalWindow);
            _windows.Add(window);

            return Ok(window);
        }