Guest User

Untitled

a guest
Nov 30th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.61 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  4. xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
  5. prism:ViewModelLocator.AutowireViewModel="True"
  6. x:Class="mySeeds.Views.StudentRedeemPage"
  7. Title="Redeem">
  8. <ContentPage.Content>
  9. <Grid x:Name="MainGrid">
  10. <Grid.RowDefinitions>
  11. <RowDefinition Height="2*" />
  12. <RowDefinition Height="3*" />
  13. </Grid.RowDefinitions>
  14. <Grid Grid.Row="0"
  15. Grid.RowSpan="1"
  16. HorizontalOptions="FillAndExpand"
  17. VerticalOptions="FillAndExpand"
  18. BackgroundColor="{StaticResource RedeemBanner}">
  19. <Grid.RowDefinitions>
  20. <RowDefinition Height="3*"/>
  21. <RowDefinition Height="1*"/>
  22. </Grid.RowDefinitions>
  23. <Grid.ColumnDefinitions>
  24. <ColumnDefinition Width="6*" />
  25. <ColumnDefinition Width="4*" />
  26. </Grid.ColumnDefinitions>
  27.  
  28. <Image Source="Icon"
  29. VerticalOptions="Center"
  30. HorizontalOptions="Center"
  31. Grid.Column="1"
  32. Grid.Row="0"/>
  33. <StackLayout Grid.Column="0"
  34. Grid.Row="0"
  35. HorizontalOptions="CenterAndExpand"
  36. VerticalOptions="Center">
  37. <Label Text="REWARD SHOP"
  38. TextColor="White"
  39. FontSize="Medium"
  40. FontAttributes="Bold"
  41. VerticalTextAlignment="Center"
  42. LineBreakMode="TailTruncation"/>
  43. <Label Text="{Binding User_Profile_Table.Points_Earned, StringFormat='{0} Seeds'}"
  44. TextColor="White"
  45. FontSize="Large"
  46. FontAttributes="Bold"
  47. VerticalTextAlignment="Center"
  48. LineBreakMode="WordWrap"/>
  49. </StackLayout>
  50. <StackLayout Grid.Row="1" Grid.ColumnSpan="2" >
  51. <Label Text="Partners" BackgroundColor="{StaticResource RedeemTab}" HorizontalOptions="FillAndExpand" VerticalOptions="Center" />
  52. <ListView
  53. Margin="0,0,0,0"
  54. HorizontalOptions="FillAndExpand"
  55. VerticalOptions="FillAndExpand"
  56. ItemsSource="{Binding ProductList}"
  57. HasUnevenRows="true"
  58. CachingStrategy="RecycleElement">
  59. <ListView.ItemTemplate>
  60. <DataTemplate>
  61. <ViewCell>
  62. <Grid Padding="0, 0, 10, 0">
  63. <Grid.RowDefinitions>
  64. <RowDefinition Height="Auto"/>
  65. </Grid.RowDefinitions>
  66. <Grid.ColumnDefinitions>
  67. <ColumnDefinition Width="30"/>
  68. <ColumnDefinition Width="*"/>
  69. <ColumnDefinition Width="Auto"/>
  70. </Grid.ColumnDefinitions>
  71. <Image x:Name="Img"
  72. Grid.Row="0" Grid.Column="0"
  73. HorizontalOptions="Center"
  74. VerticalOptions="Center"
  75. HeightRequest="30"
  76. WidthRequest="30"
  77. Source="{Binding ImageUrl}"/>
  78. <StackLayout Grid.Row="0" Grid.Column="1" VerticalOptions="Center">
  79. <Label Text="{Binding SalesPriceIncVat,StringFormat='{0} Seeds'}"
  80. TextColor="{StaticResource RedeemStatusBar}"
  81. FontAttributes="Bold"
  82. VerticalOptions="Center"/>
  83. <Label Text="{Binding Name}"
  84. VerticalOptions="Center"/>
  85. </StackLayout>
  86. <Button x:Name="btnRedeem"
  87. Text="GET IT!"
  88. TextColor="White"
  89. BackgroundColor="{StaticResource RedeemLightGreen}"
  90. Grid.Row="0" Grid.Column="2">
  91.  
  92. </Button>
  93. </Grid>
  94. </ViewCell>
  95. </DataTemplate>
  96. </ListView.ItemTemplate>
  97. </ListView>
  98.  
  99. </StackLayout>
  100. </Grid>
  101. </Grid>
  102. </ContentPage.Content>
  103. </ContentPage>
  104.  
  105. public class StudentRedeemPageViewModel : NavigationViewModelBase
  106. {
  107. private List<Data> _productList;
  108. public List<Data> ProductList
  109. {
  110. get { return _productList; }
  111. set
  112. {
  113. SetProperty(ref _productList, value);
  114. RaisePropertyChanged(nameof(ProductList));
  115. }
  116. }
  117.  
  118. private User_Profile_Table user_Profile_Table;
  119. public User_Profile_Table User_Profile_Table
  120. {
  121. get { return user_Profile_Table; }
  122. set
  123. {
  124. SetProperty(ref user_Profile_Table, value);
  125. RaisePropertyChanged(nameof(User_Profile_Table));
  126. }
  127. }
  128.  
  129. private ProductModel _product_Table;
  130. public ProductModel Product_Table
  131. {
  132. get { return _product_Table; }
  133. set
  134. {
  135. SetProperty(ref _product_Table, value);
  136. RaisePropertyChanged(nameof(Product_Table));
  137. }
  138. }
  139.  
  140. public DelegateCommand GetProductListCommand { get; private set; }
  141. public DelegateCommand UserProfileCommand { get; private set; }
  142.  
  143. public DelegateCommand NavigateToRedeemPage { get; set; }
  144.  
  145. private IRequestProvider _requestProvider;
  146.  
  147. public StudentRedeemPageViewModel(IDeviceService deviceService, INavigationService navigationService,
  148. IPageDialogService pageDialogService, IRequestProvider requestProvider)
  149. : base(deviceService, navigationService, pageDialogService)
  150. {
  151.  
  152. _requestProvider = requestProvider;
  153.  
  154. NavigateToRedeemPage = new DelegateCommand(() => NavigateCommand.Execute("VocherPage"));
  155.  
  156. GetProductListCommand = new DelegateCommand(async () => await GetProductList());
  157. UserProfileCommand = new DelegateCommand(async () => await GetUserProfile());
  158.  
  159.  
  160. UserProfileCommand.Execute();
  161. GetProductListCommand.Execute();
  162. }
  163. async Task GetProductList()
  164. {
  165. List<Data> Test = new List<Data>();
  166. string username = "admin@xxxx.com";
  167. string password = "xxxxxxxxx";
  168. string svcCredentials = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
  169.  
  170. if (svcCredentials != null)
  171. {
  172. var client = new HttpClient();
  173. client.BaseAddress = new Uri("https://xxxxxx.com/");
  174. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", svcCredentials);
  175. var productsResponse = await client.GetAsync("xxxxxx/api/xxxx/");
  176. var productsJson = productsResponse.Content.ReadAsStringAsync().Result;
  177. ProductModel members = JsonConvert.DeserializeObject<ProductModel>(productsJson);
  178. ProductList = members.Data;
  179. }
  180. }
  181.  
  182. async Task GetUserProfile()
  183. {
  184. User_Profile_Table = await _requestProvider.GetAsync<User_Profile_Table>(
  185. GlobalSetting.Instance.UserProfileTableEndpoint, Settings.AuthAccessToken);
  186. }
  187. }
  188.  
  189. public class ProductModel
  190. {
  191. public List<Data> Data { get; set; }
  192. public string FirstItem { get; set; }
  193. public string HasNextPage { get; set; }
  194. public string HasPreviousPage { get; set; }
  195. public string LastItem { get; set; }
  196. public string PageNumber { get; set; }
  197. public string PageSize { get; set; }
  198. public string TotalItems { get; set; }
  199. public string TotalPages { get; set; }
  200. }
  201.  
  202. public class Data
  203. {
  204. [JsonProperty("Data")]
  205. public string ProductId { get; set; }
  206. public string PartnerId { get; set; }
  207. public string Name { get; set; }
  208. public string Description { get; set; }
  209. public string SalesPriceIncVat { get; set; }
  210. public string SalesPriceExcVat { get; set; }
  211. public string SalesVat { get; set; }
  212. public string ValidFromDateUtc { get; set; }
  213. public string ValidToDateUtc { get; set; }
  214. public string TermsAndConditions { get; set; }
  215. public string UsageInstructions { get; set; }
  216. public string SlaTime { get; set; }
  217. public string SlaText { get; set; }
  218. public string Units { get; set; }
  219. public string StockRequired { get; set; }
  220. public string UseVariableValues { get; set; }
  221. public string MinVariableValue { get; set; }
  222. public string MaxVariableValue { get; set; }
  223. public string VariableValueAllowedIncrements { get; set; }
  224. public string ImageUrl { get; set; }
  225. public string ImageCaption { get; set; }
  226. public string CurrentStockBalance { get; set; }
  227. }
Add Comment
Please, Sign In to add comment