public DiarySummaryModel CreateSummary(Diary diary)
 {
     return new DiarySummaryModel()
       {
     DiaryDate = diary.CurrentDate,
     TotalCalories = Math.Round(diary.Entries.Sum(e => e.Measure.Calories * e.Quantity))
       };
 }
Пример #2
0
 public DiaryModel Create(Diary d)
 {
     return new DiaryModel()
     {
         Url = _urlHelper.Link("Diaries", new { diaryId = d.CurrentDate.ToString("yyyy-MM-dd") }),
         CurrentDate = d.CurrentDate
     };
 }
Пример #3
0
 public DiaryModel Create(Diary d)
 {
     return new DiaryModel()
     {
         Url = _urlHelper.Link("Diaries", new { diaryid = d.CurrentDate.ToString("yyyy-MM-dd") }),
         CurrentDate = d.CurrentDate,
         Entries = d.Entries.Select(e => Create(e))
     };
 }
Пример #4
0
 public DiaryModel Create(Diary d)
 {
     return new DiaryModel()
     {
         Links = new List<LinkModel>()
         {
             CreateLink(_urlHelp.Link("Diaries", new { diaryid = d.CurrentDate.ToString("yyyy-MM-dd")}),
                 "self")
         },
         CurrentDate = d.CurrentDate,
         Entries = d.Entries.Select(e=>Create(e))
     };
 }
Пример #5
0
 public DiaryModel Create(Diary d)
 {
     return new DiaryModel()
     {
         Links=new List<LinkModel>()
         {
             CreateLink(_urlHelper.Link("Diaries", new { diaryid= d.CurrentDate.ToString("yyyy-MM-dd") }),
                 "Self"),
             CreateLink(_urlHelper.Link("DiaryEntries", new { diaryid= d.CurrentDate.ToString("yyyy-MM-dd") }),
                 "newDiaryEntry","POST")
         },
         CurrentDate=d.CurrentDate
     };
 }
		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;
			}
		}
Пример #7
0
    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;
      }
    }