public Diary Parse(DiaryModel model) { try { var entity = new Diary { CurrentDate = model.CurrentDate }; var selfLink = model.Links.FirstOrDefault(lnk => lnk.Relation == "self"); if (!string.IsNullOrWhiteSpace(selfLink?.Href)) { var uri = new Uri(selfLink.Href); entity.Id = int.Parse(uri.Segments.Last()); } if (model.Entries != null) { foreach (var entry in model.Entries) { entity.Entries.Add(Parse(entry)); } } return(entity); } catch (Exception exc) { return(null); } }
public Diary Parse(DiaryModel model) { try { var entity = new Diary(); if (!string.IsNullOrWhiteSpace(model.Url)) { var uri = new Uri(model.Url); entity.Id = int.Parse(uri.Segments.Last()); } entity.CurrentDate = model.CurrentDate; if (model.Entries != null) { foreach (var entry in model.Entries) { entity.Entries.Add(Parse(entry)); } } return(entity); } catch { return(null); } }
public Diary Parse(DiaryModel model) { try { var entity = new Diary(); var selfLink = model.Links.Where(l => l.Rel == "self").FirstOrDefault(); if (selfLink != null && !string.IsNullOrWhiteSpace(selfLink.Href)) { var uri = new Uri(selfLink.Href); entity.Id = int.Parse(uri.Segments.Last()); } entity.CurrentDate = model.CurrentDate; if (model.Entries != null) { foreach (var entry in model.Entries) { entity.Entries.Add(Parse(entry)); } } return(entity); } catch { return(null); } }
public Diary Parse(DiaryModel diaryModel) { try { Diary diary = new Diary(); LinkModel selfLink = diaryModel.Links.Where(link => link.Rel == "self").FirstOrDefault(); if (selfLink != null && !string.IsNullOrWhiteSpace(selfLink.Href)) { Uri uri = new Uri(selfLink.Href); diary.Id = int.Parse(uri.Segments.Last()); } diary.CurrentDate = diaryModel.CurrentDate; if (diaryModel.Entries != null) { // Transfer all the entries from the model to the diary diary.Entries.ToList().AddRange( diaryModel.Entries.Select(entryModel => Parse(entryModel)) ); } return(diary); } catch { return(null); } }
public Diary Parse(DiaryModel model) { try { var entity = new Diary(); var selfLink = model.Links.FirstOrDefault(link => link.Rel == "self"); if (selfLink != null && !string.IsNullOrWhiteSpace(selfLink.Href)) { var uri = new Uri(selfLink.Href); entity.Id = int.Parse(uri.Segments.Last()); } entity.CurrentDate = model.CurrentDate; if (model.Entries != null) { foreach (var entry in model.Entries) entity.Entries.Add(Parse(entry)); } return entity; } catch { return null; } }
public Diary Parse(DiaryModel model) { try { var entity = new Diary(); if (!string.IsNullOrWhiteSpace(model.Url)) { var uri = new Uri(model.Url); entity.Id = int.Parse(uri.Segments.Last()); } entity.CurrentDate = model.CurrentDate; if (model.Entries != null) { foreach (var entry in model.Entries) entity.Entries.Add(Parse(entry)); } return entity; } catch { return null; } }