125 lines
4.3 KiB
C#
125 lines
4.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Maps;
|
|
|
|
namespace BookAStar.Pages
|
|
{
|
|
using Data;
|
|
using EstimatePages;
|
|
using Model;
|
|
using Model.Workflow;
|
|
using ViewModels.EstimateAndBilling;
|
|
|
|
public partial class BookQueryPage : ContentPage
|
|
{
|
|
|
|
public BookQueryData BookQuery
|
|
{
|
|
get
|
|
{
|
|
return (BindingContext as BookQueryViewModel).Data;
|
|
}
|
|
}
|
|
protected override void OnBindingContextChanged()
|
|
{
|
|
base.OnBindingContextChanged();
|
|
map.Pins.Clear();
|
|
if (BookQuery != null)
|
|
{
|
|
var lat = BookQuery.Location.Latitude;
|
|
var lon = BookQuery.Location.Longitude;
|
|
var pin = new Pin
|
|
{
|
|
Type = PinType.SavedPin,
|
|
Position = new Position(
|
|
lat, lon),
|
|
Label = BookQuery.Client.UserName,
|
|
Address = BookQuery.Location.Address
|
|
};
|
|
map.Pins.Add(pin);
|
|
map.MoveToRegion(MapSpan.FromCenterAndRadius(
|
|
new Position(lat, lon), Distance.FromMeters(100)));
|
|
}
|
|
|
|
}
|
|
public BookQueryPage()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public BookQueryPage(BookQueryViewModel bookQuery =null)
|
|
{
|
|
|
|
InitializeComponent();
|
|
// when TODO update?
|
|
// Task.Run( async () => { bookQuery = await App.CurrentApp.DataManager.BookQueries.Get(bookQueryId); });
|
|
|
|
BindingContext = bookQuery;
|
|
}
|
|
|
|
private void OnEditEstimate(object sender, EventArgs ev)
|
|
{
|
|
var bookQueryViewModel = (BookQueryViewModel) BindingContext;
|
|
|
|
var editEstimateViewModel = bookQueryViewModel.DraftEstimate;
|
|
if (editEstimateViewModel == null)
|
|
{
|
|
// First search for an existing estimate
|
|
editEstimateViewModel = DataManager.Current.EstimationCache.FirstOrDefault(
|
|
estimate=> estimate.Query.Id == bookQueryViewModel.Id
|
|
);
|
|
if (editEstimateViewModel == null)
|
|
{
|
|
DataManager.Current.Contacts.Merge(BookQuery.Client);
|
|
DataManager.Current.Contacts.SaveEntity();
|
|
editEstimateViewModel = new EditEstimateViewModel( new Estimate
|
|
{
|
|
ClientId = BookQuery.Client.UserId,
|
|
CommandId = BookQuery.Id,
|
|
OwnerId = MainSettings.CurrentUser.Id,
|
|
Id = 0
|
|
});
|
|
DataManager.Current.EstimationCache.Add(editEstimateViewModel);
|
|
}
|
|
}
|
|
App.NavigationService.NavigateTo<EditEstimatePage>(true,
|
|
editEstimateViewModel);
|
|
}
|
|
|
|
private async void OnViewEstimate(object sender, EventArgs ev)
|
|
{
|
|
var bookQueryViewModel = (BookQueryViewModel) BindingContext;
|
|
var buttons = bookQueryViewModel.Estimates.Select(e => $"{e.Id} / {e.Title} / {e.Total}").ToArray();
|
|
var action = await App.DisplayActionSheet("Estimations validées", "Annuler", null, buttons);
|
|
if (buttons.Contains(action))
|
|
{
|
|
var index = Array.IndexOf(buttons,action);
|
|
var estimate = bookQueryViewModel.Estimates[index];
|
|
App.NavigationService.NavigateTo<ViewEstimatePage>(true,
|
|
new EditEstimateViewModel(estimate));
|
|
}
|
|
}
|
|
|
|
protected override void OnSizeAllocated(double width, double height)
|
|
{
|
|
if (width > height)
|
|
{
|
|
bookQueryLayout.Orientation = StackOrientation.Horizontal;
|
|
}
|
|
else
|
|
{
|
|
bookQueryLayout.Orientation = StackOrientation.Vertical;
|
|
}
|
|
base.OnSizeAllocated(width, height);
|
|
}
|
|
private void OnBlockThisUser(object sender, EventArgs ev)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
private void OnDropQuery(object sender, EventArgs ev)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|