Beispiel #1
0
        public HttpResponseMessage Get(DateTime diaryid)
        {
            var username = _identityService.CurrentUser;
            var result   = TheRepo.GetDiary(username, diaryid);

            if (result == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(result)));
        }
Beispiel #2
0
 public object Get(DateTime diaryid)
 {
     try
     {
         var diary = TheRepo.GetDiary(_identityService.CurrentUser, diaryid);
         if (diaryid == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound));
         }
         return(TheModelFactory.CreateSummary(diary));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Beispiel #3
0
        public HttpResponseMessage Post(DateTime diaryid, [FromBody] DiaryEntryModel model)
        {
            try
            {
                var entity = TheModelFactory.Parse(model);
                if (entity == null)
                {
                    Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body");
                }
                var diary = TheRepo.GetDiary(_identityService.CurrentUser, diaryid);
                if (diary == null)
                {
                    Request.CreateResponse(HttpStatusCode.NotFound);
                }

                //Make sure it's not duplicate
                if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate Measure not allowed"));
                }

                //Save the new Entry
                diary.Entries.Add(entity);
                if (TheRepo.SaveAll())
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity)));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save in the database"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }