Exemple #1
0
        public DiaryEntry Parse(DiaryEntryModel model)
        {
            try
            {
                var entry = new DiaryEntry();
                if (model.Quantity != default(double))
                {
                    entry.Quantity = model.Quantity;
                }

                if (!string.IsNullOrWhiteSpace(model.MeasureUrl))
                {
                    var uri = new Uri(model.MeasureUrl);
                var measureId = int.Parse(uri.Segments.Last());
                var measure = _repo.GetMeasure(measureId);
                entry.Measure = measure;
                entry.FoodItem = measure.Food;
                }
                   
            return entry;
            }
            catch 
            {

                return null;
            }
        }
Exemple #2
0
 public DiaryEntryModel Create(DiaryEntry diaryEntry)
 {
     return new DiaryEntryModel()
     {
         Url = _urlHelper.Link("DiariresEntries", new { diaryid = diaryEntry.Diary.CurrentDate.ToString("yyyy-MM-dd"), id = diaryEntry.Id }),
         FoodDescription = diaryEntry.FoodItem.Description,
         MeasureDescription =diaryEntry.Measure.Description,
         MeasureUrl = _urlHelper.Link("Measures", new { foodid = diaryEntry.Measure.Food.Id, id = diaryEntry.Measure.Id }),
         Quantity=diaryEntry.Quantity
     };
 }