Esempio n. 1
0
        public HttpResponseMessage Post(
            int projectId, int activityId, TimelogViewModel model)
        {
            Activity activity = GetActivity(projectId, activityId);

            DateTime date;
            if (!DateTime.TryParse(model.Date, out date))
            {
                date = DateTime.Now;
            }

            Timelog timelog = Timelog.Forge(model.Description, model.Duration, date,
                                                      Request.GetCurrentPersonId());
            timelog.Id = activity.GenerateNewTimeEntryId();
            activity.Timelogs.Add(timelog);

            TimelogViewModel value = Mapper.Map<Timelog, TimelogViewModel>(timelog);
            value.Activity = activityId;
            return Request.CreateResponse(HttpStatusCode.Created, value);
        }
Esempio n. 2
0
        public HttpResponseMessage Put(
            int projectId, int activityId, TimelogViewModel model)
        {
            Activity activity = GetActivity(projectId, activityId);

            DateTime date;
            if (!DateTime.TryParse(model.Date, out date))
            {
                date = DateTime.Now;
            }

            var timelog = activity.Timelogs.FirstOrDefault(t => t.Id == model.Id);
            if(timelog == null)
                throw new HttpResponseException(HttpStatusCode.NotFound);

            timelog.Date = date;
            timelog.Description = model.Description;
            timelog.Duration = model.Duration;

            TimelogViewModel value = Mapper.Map<Timelog, TimelogViewModel>(timelog);
            value.Activity = activityId;
            return Request.CreateResponse(HttpStatusCode.Created, value);
        }