public VisitorPickerViewController()
			: base(new UICollectionViewFlowLayout())
		{

			this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add,(sender,args)=>
			{
				//if (CreateNew != null) CreateNew();
				var visitVc = new EditVisitorViewController()
				{
					Visitor = new VMVisitor()
					{
						Visitor = new Visitor(),
					},
					Selected = (visit) =>
					{
						if (Selected != null)
							Selected(visit);
					}
				};
				this.NavigationController.PushViewController(visitVc,true);
			});
			CollectionView.RegisterClassForCell(typeof(Source.VisitCell), Source.VisitCell.Identifier);
			CollectionView.Source = source = new Source();
			CollectionView.BackgroundColor = View.BackgroundColor = UIColor.FromRGB(239, 239, 244);
			CollectionView.ContentInset = new UIEdgeInsets(10,20,0,20);
			Title = "Who is visiting?";
		}
 public VisitorPickerViewController()
     : base(new UICollectionViewFlowLayout())
 {
     this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, (sender, args) =>
     {
         //if (CreateNew != null) CreateNew();
         var visitVc = new EditVisitorViewController()
         {
             Visitor = new VMVisitor()
             {
                 Visitor = new Visitor(),
             },
             Selected = (visit) =>
             {
                 if (Selected != null)
                 {
                     Selected(visit);
                 }
             }
         };
         this.NavigationController.PushViewController(visitVc, true);
     });
     CollectionView.RegisterClassForCell(typeof(Source.VisitCell), Source.VisitCell.Identifier);
     CollectionView.Source          = source = new Source();
     CollectionView.BackgroundColor = View.BackgroundColor = UIColor.FromRGB(239, 239, 244);
     CollectionView.ContentInset    = new UIEdgeInsets(10, 20, 0, 20);
     Title = "Who is visiting?";
 }
			public VisitDetailsView(VisitDetailsViewController parent)
			{
				Parent = parent;
				BackgroundColor = UIColor.FromRGB(239,239,244);

				addVisitor = new UIButton
				{
					Frame = new RectangleF(0, 0, 150, 150),
					TintColor = UIColor.White,
					Layer =
					{
						CornerRadius = 75,
						MasksToBounds = true,
					}
				};
				addVisitor.SetTitle("Add a visitor", UIControlState.Normal);
				addVisitor.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;;
				addVisitor.SetImage(Theme.UserImageDefaultLight.Value,UIControlState.Normal);
				addVisitor.TouchUpInside += (sender, args) => { if (Parent.PickVisitor != null) Parent.PickVisitor(); };
				AddSubview(addVisitor);

				addEmployee = new UIButton
				{
					Frame = new RectangleF(0, 0, 150, 150),
					TintColor = UIColor.White,
					Layer =
					{
						CornerRadius = 75,
						MasksToBounds = true,
					}
				};
				addEmployee.SetTitle("Add an employee", UIControlState.Normal);
				addEmployee.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill; ;
				addEmployee.SetImage(Theme.UserImageDefaultLight.Value, UIControlState.Normal);
				addEmployee.TouchUpInside += (sender, args) => { if (Parent.PickEmployee != null) Parent.PickEmployee(); };
				AddSubview(addEmployee);

				editButton = new UIButton(new RectangleF(0,0,40,40));
				editButton.SetBackgroundImage(UIImage.FromBundle("edit"),UIControlState.Normal );
				editButton.TouchUpInside += (sender, args) =>
				{
					var vc = new EditVisitorViewController
					{
						Visitor = new VMVisitor{Visitor = visit.Visitor}
					};
					this.Parent.NavigationController.PushViewController(vc,true);
				};

				visitorLabel = new UILabel { Text = "Visitor", Font = UIFont.FromName(font2, 30), TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true,};

				visitorLabel.SizeToFit();
				AddSubview(visitorLabel);

				employeeLabel = new UILabel { Text = "Employee", Font = UIFont.FromName(font2, 30), TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true,};
				employeeLabel.SizeToFit();
				AddSubview(employeeLabel);

				date = new DateTimeElement("Date", DateTime.Now);
				comment = new EntryElement("Reason: ", "Reason", "");
				comment.Changed += (sender, args) =>
				{
					Console.WriteLine("Comment");
				};
				vehicle = new BooleanElement("Vehicle",false);
				licensePlate = new EntryElement("Lic Plate: ", "License Plate", "");
				licensePlate.Changed += (sender, args) =>
				{
					Console.WriteLine("licensePlate");
				};
				vehicle.ValueChanged += (sender, args) =>
				{
					if (vehicle.Value)
					{
						if (!section.Elements.Contains(licensePlate))
							section.Add(licensePlate);
						datadvc.ReloadData();
					}
					else
					{
						licensePlate.FetchValue();
						section.Remove(licensePlate);
					}
				};


				datadvc = new DialogViewController(new RootElement("visit")
				{
					(section = new Section
					{
						date,
						comment,
						vehicle,
						licensePlate
					})
				});
				datadvc.TableView.SectionHeaderHeight = 0;
				datadvc.TableView.TableHeaderView = null;
				datadvc.View.BackgroundColor = UIColor.White;
				datadvc.View.Layer.CornerRadius = 5f;
				var height = Enumerable.Range(0, datadvc.TableView.Source.RowsInSection(datadvc.TableView,0)).Sum(x => datadvc.TableView.Source.GetHeightForRow(datadvc.TableView, NSIndexPath.FromRowSection(x, 0)));
				datadvc.View.Frame = new RectangleF(0,0,100,height);
				AddSubview(datadvc.View);
				this.Parent.AddChildViewController(datadvc);


			}
            public EditVisitorView(EditVisitorViewController parent)
            {
                BackgroundColor = UIColor.FromRGB(239, 239, 244);

                image = new UIButton
                {
                    Frame     = new RectangleF(0, 0, 150, 150),
                    TintColor = UIColor.White,
                    Layer     =
                    {
                        CornerRadius  =   75,
                        MasksToBounds = true,
                    }
                };
                image.SetTitle("Change photo", UIControlState.Normal);
                image.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;;
                image.SetImage(Theme.UserImageDefaultLight.Value, UIControlState.Normal);
                image.TouchUpInside += async(sender, args) =>
                {
                    try
                    {
                        var picker     = new MediaPicker();
                        var controller = picker.GetTakePhotoUI(new StoreCameraMediaOptions
                        {
                            Name      = "test.jpg",
                            Directory = "MediaPickerSample"
                        });

                        parent.PresentViewController(controller, true, null);

                        var result = await controller.GetResultAsync();

                        var     i = UIImage.FromFile(result.Path).ResizeImage(380, 380);
                        NSError error;
                        i.AsJPEG().Save(result.Path, NSDataWritingOptions.FileProtectionNone, out error);

                        Console.WriteLine("Result came back");
                        Console.WriteLine(result);
                        Console.WriteLine(result.Path);

                        var picture = new VisitorPicture
                        {
                            Content     = File.ReadAllBytes(result.Path),
                            PictureType = PictureType.Small,
                        };

                        var picture2 = new VisitorPicture
                        {
                            Content     = File.ReadAllBytes(result.Path),
                            PictureType = PictureType.Big,
                        };

                        image.SetImage(UIImage.FromFile(result.Path) ?? Theme.UserImageDefaultLight.Value, UIControlState.Normal);
                        Visitor.ClearPhotos();
                        Visitor.AddPicture(picture);
                        Visitor.AddPicture(picture2);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                    finally
                    {
                        parent.DismissViewController(true, null);
                    }
                };

                AddSubview(image);

                dvc = new DialogViewController(new RootElement("Visitor")
                {
                    new Section("Visitor")
                    {
                        (firstName = new EntryElement("First name", "John", "")),
                        (lastName = new EntryElement("Last name", "Apleseed", "")),
                        (idNumber = new EntryElement("Id number", "123456", "")),
                        (email = new EntryElement("Email", "*****@*****.**", "")),
                        (company = new EntryElement("Organization/ Company", "MyCompany", "")),
                        (title = new EntryElement("Proffesional Title", "CEO", ""))
                    }
                })
                {
                    TableView =
                    {
                        SectionHeaderHeight =             0,
                        BackgroundColor     = UIColor.White,
                        Layer               =
                        {
                            CornerRadius  =             5,
                            MasksToBounds = true
                        }
                    }
                };

                this.AddSubview(dvc.View);
                parent.AddChildViewController(dvc);
            }
			public EditVisitorView(EditVisitorViewController parent)
			{
				BackgroundColor = UIColor.FromRGB(239, 239, 244);

				image = new UIButton
				{
					Frame = new RectangleF(0, 0, 150, 150),
					TintColor = UIColor.White,
					Layer =
					{
						CornerRadius = 75,
						MasksToBounds = true,
					}
				};
				image.SetTitle("Change photo", UIControlState.Normal);
				image.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;;
				image.SetImage(Theme.UserImageDefaultLight.Value,UIControlState.Normal);
				image.TouchUpInside += async (sender, args) =>
				{
					try
					{
						var picker = new MediaPicker();
						var controller = picker.GetTakePhotoUI(new StoreCameraMediaOptions
						{
							Name = "test.jpg",
							Directory = "MediaPickerSample"
						});

						//var popupver = new UIPopoverController(controller);
						//popupver.PresentFromRect(image.Frame,this, UIPopoverArrowDirection.Any, true);
						parent.PresentViewController(controller, true, null);

						var result = await controller.GetResultAsync();
						var i = UIImage.FromFile(result.Path).ResizeImage(380,380);
						NSError error;
						i.AsJPEG().Save(result.Path, NSDataWritingOptions.FileProtectionNone, out error);
						
						Console.WriteLine("Result came back");
						Console.WriteLine(result);
						Console.WriteLine(result.Path);
						
						var picture = new VisitorPicture
						{
							Content = File.ReadAllBytes(result.Path),
							PictureType = PictureType.Small,
						};

						var picture2 = new VisitorPicture
						{
							Content = File.ReadAllBytes(result.Path),
							PictureType = PictureType.Big,
						};

						image.SetImage(UIImage.FromFile(result.Path) ?? Theme.UserImageDefaultLight.Value, UIControlState.Normal);
						Visitor.ClearPhotos();
						Visitor.AddPicture(picture);
						Visitor.AddPicture(picture2);
					}
					catch (Exception ex)
					{
						Console.WriteLine(ex);
					}
					finally
					{
						parent.DismissViewController(true,null);
					}
					
					//popupver.Dismiss(true);

				};

				AddSubview(image);

				dvc = new DialogViewController(new RootElement("Visitor")
				{
					new Section("Visitor")
					{
						(firstName = new EntryElement("First name", "John","")),
						(lastName = new EntryElement("Last name","Apleseed","")),
						(idNumber = new EntryElement("Id number","123456","")),
						(email = new EntryElement("Email", "*****@*****.**","")),
						(company = new EntryElement("Organization/ Company","MyCompany","")),
						(title = new EntryElement("Proffesional Title","CEO",""))
					}
				})
				{
					TableView =
					{
						SectionHeaderHeight = 0,
						BackgroundColor = UIColor.White,
						Layer =
						{
							CornerRadius = 5,
							MasksToBounds = true
						}
					}
				};
				
				this.AddSubview(dvc.View);
				parent.AddChildViewController(dvc);
			}
            public VisitDetailsView(VisitDetailsViewController parent)
            {
                Parent          = parent;
                BackgroundColor = UIColor.FromRGB(239, 239, 244);

                addVisitor = new UIButton
                {
                    Frame     = new RectangleF(0, 0, 150, 150),
                    TintColor = UIColor.White,
                    Layer     =
                    {
                        CornerRadius  =   75,
                        MasksToBounds = true,
                    }
                };
                addVisitor.SetTitle("Add a visitor", UIControlState.Normal);
                addVisitor.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;;
                addVisitor.SetImage(Theme.UserImageDefaultLight.Value, UIControlState.Normal);
                addVisitor.TouchUpInside += (sender, args) => { if (Parent.PickVisitor != null)
                                                                {
                                                                    Parent.PickVisitor();
                                                                }
                };
                AddSubview(addVisitor);

                addEmployee = new UIButton
                {
                    Frame     = new RectangleF(0, 0, 150, 150),
                    TintColor = UIColor.White,
                    Layer     =
                    {
                        CornerRadius  =   75,
                        MasksToBounds = true,
                    }
                };
                addEmployee.SetTitle("Add an employee", UIControlState.Normal);
                addEmployee.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;;
                addEmployee.SetImage(Theme.UserImageDefaultLight.Value, UIControlState.Normal);
                addEmployee.TouchUpInside += (sender, args) => { if (Parent.PickEmployee != null)
                                                                 {
                                                                     Parent.PickEmployee();
                                                                 }
                };
                AddSubview(addEmployee);

                editButton = new UIButton(new RectangleF(0, 0, 40, 40));
                editButton.SetBackgroundImage(UIImage.FromBundle("edit"), UIControlState.Normal);
                editButton.TouchUpInside += (sender, args) =>
                {
                    var vc = new EditVisitorViewController
                    {
                        Visitor = new VMVisitor {
                            Visitor = visit.Visitor
                        }
                    };
                    this.Parent.NavigationController.PushViewController(vc, true);
                };

                visitorLabel = new UILabel {
                    Text = "Visitor", Font = UIFont.FromName(font2, 30), TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true,
                };

                visitorLabel.SizeToFit();
                AddSubview(visitorLabel);

                employeeLabel = new UILabel {
                    Text = "Employee", Font = UIFont.FromName(font2, 30), TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true,
                };
                employeeLabel.SizeToFit();
                AddSubview(employeeLabel);

                date             = new DateTimeElement("Date", DateTime.Now);
                comment          = new EntryElement("Reason: ", "Reason", "");
                comment.Changed += (sender, args) =>
                {
                    Console.WriteLine("Comment");
                };
                vehicle               = new BooleanElement("Vehicle", false);
                licensePlate          = new EntryElement("Lic Plate: ", "License Plate", "");
                licensePlate.Changed += (sender, args) =>
                {
                    Console.WriteLine("licensePlate");
                };
                vehicle.ValueChanged += (sender, args) =>
                {
                    if (vehicle.Value)
                    {
                        if (!section.Elements.Contains(licensePlate))
                        {
                            section.Add(licensePlate);
                        }
                        datadvc.ReloadData();
                    }
                    else
                    {
                        licensePlate.FetchValue();
                        section.Remove(licensePlate);
                    }
                };


                datadvc = new DialogViewController(new RootElement("visit")
                {
                    (section = new Section
                    {
                        date,
                        comment,
                        vehicle,
                        licensePlate
                    })
                });
                datadvc.TableView.SectionHeaderHeight = 0;
                datadvc.TableView.TableHeaderView     = null;
                datadvc.View.BackgroundColor          = UIColor.White;
                datadvc.View.Layer.CornerRadius       = 5f;
                var height = Enumerable.Range(0, datadvc.TableView.Source.RowsInSection(datadvc.TableView, 0)).Sum(x => datadvc.TableView.Source.GetHeightForRow(datadvc.TableView, NSIndexPath.FromRowSection(x, 0)));

                datadvc.View.Frame = new RectangleF(0, 0, 100, height);
                AddSubview(datadvc.View);
                this.Parent.AddChildViewController(datadvc);
            }