public IHttpActionResult Create(AddDayRequest day)
        {
            if (day == null || !ModelState.IsValid)
            {
                return(ResponseMessage(CreateCustomResponseMessage(HttpStatusCode.BadRequest)));
            }
            var result = _dayService.Add(day);

            return(ResponseMessage(CreateCustomResponseMessage(result)));
        }
示例#2
0
        public ServiceResponse <DayResponse> Add(AddDayRequest dayRequest)
        {
            using (DiaryContext db = new DiaryContext())
            {
                var diary = db.Diaries.FirstOrDefault(x => x.Id == dayRequest.DiaryId);
                if (diary == null)
                {
                    return(new ServiceResponse <DayResponse>(null, HttpStatusCode.NotFound, "Unable to find the diary!"));
                }

                var day = new Day
                {
                    Date  = dayRequest.Date,
                    Diary = diary,
                };
                Day _day = db.Days.Add(day);
                db.SaveChanges();
                return(new ServiceResponse <DayResponse>(new DayResponse(_day, typeof(DayResponse)), HttpStatusCode.OK, "Day added succesfully!"));
            }
        }