public Diary Parse(DiaryModel model)
        {
            try
            {
                var entity = new Diary();

                var selfLink = model.Links.FirstOrDefault(l => l.Rel == SELF_REL);
                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.DiaryEntries != null)
                {
                    foreach (var entryModel in model.DiaryEntries)
                    {
                        var entry = Parse(entryModel);
                        entity.Entries.Add(entry);
                    }
                }

                return(entity);
            }
            catch
            {
                return(null);
            }
        }
        public DiaryModel Create(Diary diary)
        {
            var selfHref = _urlHelper.Link(DIARIES_ROUTE, new { diaryid = diary.CurrentDate.ToString(DIARY_DATE_FORMAT) });
            var selfLink = CreateLink(selfHref, SELF_REL);

            var diaryEntryHref = _urlHelper.Link(DIARY_ENTRIES_ROUTE, new { diaryid = diary.CurrentDate.ToString(DIARY_DATE_FORMAT) });
            var diaryEntryLink = CreateLink(diaryEntryHref, NEW_DIARY_ENTRY_REL, POST);

            var model = new DiaryModel
            {
                Links = new List <LinkModel>
                {
                    selfLink,
                    diaryEntryLink
                },
                CurrentDate  = diary.CurrentDate,
                DiaryEntries = diary.Entries.Select(e => Create(e))
            };

            return(model);
        }