This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CountriesViewModel | |
{ | |
const string url = "http://country.io/names.json"; | |
public async Task<Dictionary<string, string>> GetCountriesData() | |
{ | |
try | |
{ | |
var httpClient = new HttpClient(); | |
var countries = await httpClient.GetStringAsync(url); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Countries | |
{ | |
public string CountryCode { get; set; } | |
public string CountryName { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Countries | |
{ | |
[EnumDescription(Text="India")] | |
India, | |
[EnumDescription(Text = "South Africa")] | |
SouthAfrica, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class EnumsHelper | |
{ | |
public static T GetAttributeOfType<T>(this Enum enumVal) where T : Attribute | |
{ | |
var typeInfo = enumVal.GetType().GetTypeInfo(); | |
var v = typeInfo.DeclaredMembers.First(x => x.Name == enumVal.ToString()); | |
return v.GetCustomAttribute<T>(); | |
} | |
public static string GetDescription(this Enum enumVal) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EnumDescriptionAttribute : Attribute | |
{ | |
public virtual string DisplayName { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ItemsTableView.Source = new TableSource (Names); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
searchBar.SearchButtonClicked += (sender, e) => { | |
var listItems = Utilities.Names.Where (m => m.ToString ().StartsWith (searchBar.Text.Trim ())).ToList (); | |
ItemsTableView.Source = new TableSource (listItems); | |
ItemsTableView.ReloadData (); | |
searchBar.ResignFirstResponder (); | |
}; | |
searchBar.TextChanged += (sender, e) => { | |
var listItems = Utilities.Names.Where (m => m.ToString ().StartsWith (searchBar.Text.Trim ())).ToList (); | |
ItemsTableView.Source = new TableSource (listItems); | |
ItemsTableView.ReloadData (); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TableSource : UITableViewSource | |
{ | |
List<string> tableItems; | |
string cellIdentifier = "TableCell"; | |
public TableSource (List<string> items) | |
{ | |
tableItems = items; | |
} | |
public override nint RowsInSection (UITableView tableview, nint section) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void RegisterGlobalFilter(GlobalFilterCollection filters) | |
{ | |
filters.Add(new HandleErrorAttribute()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HandleError(View = "ErrorView")] | |
public ActionResult Index() | |
{ | |
try | |
{ | |
//Logic | |
} | |
catch (Exception ex) | |
{ | |
throw ex; |