Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roman Makarevych. implemented tasks #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions UndoAssessment/UndoAssessment/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public App ()
InitializeComponent();

DependencyService.Register<MockDataStore>();
DependencyService.Register<PublicApi>();
MainPage = new AppShell();
}

Expand Down
15 changes: 15 additions & 0 deletions UndoAssessment/UndoAssessment/Models/FailModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace UndoAssessment.Models
{
public class FailModel
{
public string Message { get; set; }

public DateTime Date { get; set; }

public int ErrorCode { get; set; }
}
}
14 changes: 14 additions & 0 deletions UndoAssessment/UndoAssessment/Models/SuccessModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace UndoAssessment.Models
{
public class SuccessModel
{
public string Message { get; set; }

public DateTime Date { get; set; }

}
}
19 changes: 19 additions & 0 deletions UndoAssessment/UndoAssessment/Services/IPublicApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Refit;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using UndoAssessment.Models;

namespace UndoAssessment.Services
{
public interface IPublicApi
{
[Get("/success")]
Task<SuccessModel> GetSuccess();

[Get("/fail")]
Task<FailModel> GetFail();
}
}
27 changes: 27 additions & 0 deletions UndoAssessment/UndoAssessment/Services/PublicApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Refit;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using UndoAssessment.Models;

namespace UndoAssessment.Services
{
public class PublicApi
{
IPublicApi api;
public PublicApi()
{
api = RestService.For<IPublicApi>("https://malkarakundostagingpublicapi.azurewebsites.net");
}
public Task<FailModel> GetFail()
{
return api.GetFail();
}

public Task<SuccessModel> GetSuccess()
{
return api.GetSuccess();
}
}
}
1 change: 1 addition & 0 deletions UndoAssessment/UndoAssessment/UndoAssessment.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Refit" Version="7.0.0" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.6" />
</ItemGroup>
Expand Down
31 changes: 4 additions & 27 deletions UndoAssessment/UndoAssessment/Views/ItemsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,9 @@
x:DataType enables compiled bindings for better performance and compile time validation of binding expressions.
https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/data-binding/compiled-bindings
-->
<RefreshView x:DataType="local:ItemsViewModel" Command="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
<CollectionView x:Name="ItemsListView"
ItemsSource="{Binding Items}"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Padding="10" x:DataType="model:Item">
<Label Text="{Binding Text}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16" />
<Label Text="{Binding Description}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemDetailTextStyle}"
FontSize="13" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
NumberOfTapsRequired="1"
Command="{Binding Source={RelativeSource AncestorType={x:Type local:ItemsViewModel}}, Path=ItemTapped}"
CommandParameter="{Binding .}">
</TapGestureRecognizer>
</StackLayout.GestureRecognizers>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
<StackLayout>
<Button Text="Success" Clicked="Success_Clicked"></Button>
<Button Text="Fail" Clicked="Fail_Clicked"></Button>
</StackLayout>
</ContentPage>

33 changes: 31 additions & 2 deletions UndoAssessment/UndoAssessment/Views/ItemsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@
using UndoAssessment.Models;
using UndoAssessment.Views;
using UndoAssessment.ViewModels;
using UndoAssessment.Services;

namespace UndoAssessment.Views
{
public partial class ItemsPage : ContentPage
{
ItemsViewModel _viewModel;

public ItemsPage()
PublicApi publicApi;
public ItemsPage(PublicApi publicApi)
{
InitializeComponent();

this.publicApi = publicApi;
BindingContext = _viewModel = new ItemsViewModel();
}

Expand All @@ -29,5 +31,32 @@ protected override void OnAppearing()
base.OnAppearing();
_viewModel.OnAppearing();
}

private async void Success_Clicked(object sender, EventArgs e)
{
try
{
var result = await publicApi.GetSuccess();
await DisplayAlert("Get success", $"Message: {result.Message}", "OK");
}
catch (Exception ex)
{
await DisplayAlert("Error during call api", $"Message: {ex.Message}", "OK");
}
}

private async void Fail_Clicked(object sender, EventArgs e)
{
try
{
var result = await publicApi.GetFail();

await DisplayAlert("Get fail", $"Message: {result.Message}", "OK");
}
catch (Exception ex)
{
await DisplayAlert("Error during call api", $"Message: {ex.Message}", "OK");
}
}
}
}