public async Task <Goetia> GetByIDAsync(int id) { Goetia goetia = new Goetia(); try { List <ScanCondition> conditions = new List <ScanCondition> { new ScanCondition(nameof(Goetia.ID), ScanOperator.Equal, id) }; var results = await _Context.ScanAsync <Goetia>(conditions).GetRemainingAsync(); goetia = results.FirstOrDefault(); goetia.Success = true; } catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); goetia.Success = false; } catch (AmazonServiceException e) { Console.WriteLine(e.Message); goetia.Success = false; } catch (Exception e) { Console.WriteLine(e.Message); goetia.Success = false; goetia.Message = e.Message; } return(goetia); }
public async Task <bool> SaveAsync(Goetia item) { DynamoDBOperationConfig config = new DynamoDBOperationConfig { IgnoreNullValues = true, Conversion = DynamoDBEntryConversion.V2 // allows duplicate (this is used for keyword }; try { await _Context.SaveAsync(item, config); return(true); } catch (Exception ex) { Console.WriteLine(ex.Message + $" ID: {item.ID}"); return(false); } }
private void ParseItemToListViewmodels(Goetia item) { // update the list viewmodel Type type = item.GetType(); BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; PropertyInfo[] properties = type.GetProperties(flags); foreach (PropertyInfo property in properties) { // excluding Keywords, Direction, ImageURL, BaseModel, ID, Name, Description if (property.Name != nameof(Goetia.Keywords) && property.Name != nameof(Goetia.Direction) && property.Name != nameof(Goetia.ImageURL) && property.Name != nameof(Goetia.Success) && property.Name != nameof(Goetia.Message) && property.Name != nameof(Goetia.ID) && property.Name != nameof(Goetia.Name) && property.Name != nameof(Goetia.Description)) { string name = property.Name; object propertyValue = property.GetValue(GoetiaItem, null); if (propertyValue != null) { string info = ""; // we're expecting string or list of string if (propertyValue is string) { info = propertyValue as string; ListViewModels.Add(new GoetiaDetailInformationViewModel($"{name} : ", info)); } else if (propertyValue is List <string> ) { List <string> list = propertyValue as List <string>; if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { info += list[i]; if (i + 1 < list.Count) { info += ", "; } } ListViewModels.Add(new GoetiaDetailInformationViewModel($"{name} : ", info)); } } } } } }
public GoetiaDetailContentPage(Goetia goetia) { ViewModel.GoetiaItem = goetia; this.Setup(); UpdateViewAsync(); }