示例#1
0
 public static async Task<bool> UpdateStatus(Prospect p, API.Status status)
 {
     var client = new HttpClient();
     p.Status = (int)status;
     var data = Newtonsoft.Json.JsonConvert.SerializeObject(p);
     var content = new StringContent(data, Encoding.UTF8, "application/json");
     var url = string.Format("{0}/{1}", API.ProspectsAPI, p.ProspectID);
     var response = await client.PutAsync( url, content);
     //PUT returns empty content, so we only care if the update was succesfull or not. In case of success server return 204
     return response.IsSuccessStatusCode;
 }
示例#2
0
        private void CreateCustomCell(Prospect prospect, int i, MainViewModel vm)
        {

            this.Prospects.Children.Add(
                   
                    new TableView
                    {
                        HasUnevenRows = true,
                        BackgroundColor = Color.Transparent, // Xamarin.Forms.Color.FromHex("8fc1d0"),
                        Opacity = 70.0,
                        VerticalOptions = LayoutOptions.CenterAndExpand,
                        HeightRequest = (Device.OS == TargetPlatform.iOS) ? this.Height * 1.25 / 10 : this.Height * 2.5 / 10,
                        Root = new TableRoot
                        {
                            new TableSection
                            {
                                new ProspectCustomCell(
                                    new Label {Text = prospect.Name}, i, vm.Prospects.Count, this,prospect)
                            }
                        }
                    }
                );
        }
 public ProspectDetailViewModel(Prospect prospect)
 {
     Title = "Prospect Detail";
     _prospect = prospect;
     
 }
        static Contact ConvertPropectToContact(Prospect prospect)
        {
            var contact = new Contact
            {
                Address = prospect.Location,
                Name = prospect.Name,
                Notes = prospect.Notes,
                Phone = prospect.Phone,
                PicUrl = prospect.PicUrl
            };

            return contact;
        }
        public ProspectCustomCell(Label label, int position, int positionsCount, VisualElement parent, Prospect prospect)
        {
            label.LineBreakMode = LineBreakMode.WordWrap;
            label.TextColor = Color.White;
            AddGestures(label, parent, prospect);

            var buttonsRow = new Grid
            {
                ColumnDefinitions =
                {

                    new ColumnDefinition {Width = new GridLength(25, GridUnitType.Absolute)},
                    new ColumnDefinition {Width = new GridLength(25, GridUnitType.Absolute)},
                    new ColumnDefinition {Width = new GridLength(25, GridUnitType.Absolute)},
                },
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                Padding = 5,
                Children = { { _infoButtonImage, 0, 0 }, { _plusButtonImage, 1, 0 }, { _minusButtonImage, 2, 0 } }
            };

            var row = new Grid
            {

                ColumnDefinitions =
                {
                    new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)},
                    new ColumnDefinition {Width = new GridLength(60, GridUnitType.Star)},
                    new ColumnDefinition {Width = new GridLength(38, GridUnitType.Star)},
                    new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)},

                },

                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                Children = { { label, 1, 0 }, { buttonsRow, 2, 0 } }
            };

            var positions = new Grid
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                ColumnSpacing = 5,
            };
            for (int i = 0; i < positionsCount; i++)
            {
                positions.Children.Add(new Image { Source = i == position ? ImageOn : ImageOff }, i, 0);
                positions.ColumnDefinitions.Add(new ColumnDefinition { Width = 10 });
            }

            var content = new Grid
            {
                RowDefinitions =
                {
                    new RowDefinition{Height = new GridLength(80, GridUnitType.Star) },
                    new RowDefinition{Height = new GridLength(20, GridUnitType.Star)}
                },
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions = LayoutOptions.Center,
                Children = { { row, 0, 0 }, { positions, 0, 1 } },
                BackgroundColor = Color.Teal

            };

            this.View = content;
            this.View.VerticalOptions = LayoutOptions.CenterAndExpand;
        }
        private void AddGestures(Label ttd, VisualElement parent, Prospect prospect)
        {
            var tapInfoButton = new TapGestureRecognizer();
            tapInfoButton.Tapped += (s, e) =>
            parent.Navigation.PushModalAsync(new ProspectDetailView
            {
                PDvm = new ProspectDetailViewModel(prospect)
            }, false);
            ttd.GestureRecognizers.Add(tapInfoButton);
            _infoButtonImage.GestureRecognizers.Add(tapInfoButton);

            var tapPlus = new TapGestureRecognizer();
            tapPlus.Tapped += async (s, e) =>
            {
                var p = ConvertPropectToContact(prospect);
                await ProspectDetailViewModel.AddContact(p);
                await API.UpdateStatus(prospect, API.Status.Converted);
                await parent.Navigation.PushModalAsync(new MainView());
            };
            _plusButtonImage.GestureRecognizers.Add(tapPlus);

            var tapMinus = new TapGestureRecognizer();
            tapMinus.Tapped += async (s, e) =>
            {
                var contact = ConvertPropectToContact(prospect);
                await API.UpdateStatus (prospect, API.Status.Ignored);
                await parent.Navigation.PushModalAsync(new MainView());
            };
            _minusButtonImage.GestureRecognizers.Add(tapMinus);
        }