예제 #1
0
        public HttpResponseMessage Put(int projectId,
                                       CompleteActivityViewModel model)
        {
            var activity = DbSession
                .Load<Activity>(model.Id);

            if (activity == null || activity.Project.ToIdentifier() != projectId)
                throw new HttpResponseException(HttpStatusCode.NotFound);

            activity.Update(model.MapTo<Activity>(), DbSession);

            var activities = activity.MapTo<ActivityViewModel>();
            return Request.CreateResponse(HttpStatusCode.Created, activities);
        }
예제 #2
0
        public HttpResponseMessage Post(int projectId, CompleteActivityViewModel model)
        {
            var project = DbSession.Load<Project>(projectId);
            var activity = Activity.Forge(projectId, model.Name, model.Description, model.Duration);

            DbSession.Store(activity);
            if (model.Dependencies != null)
                activity.Dependencies = model.Dependencies.Select(s => s.ToId("activity")).ToList();

            var domain = DbSession.Query<Activity>()
                .Where(a => a.Project == project.Id).ToList();

            activity.StartDateConsecutive = activity.StartDate = model.StartDate;

            var value = activity.MapTo<ActivityViewModel>();
            var response = Request.CreateResponse(HttpStatusCode.Created, value);

            var uri = Url.Link("api_activities_getbyid", new {projectId, id = activity.Id.ToIdentifier()});
            response.Headers.Location = new Uri(uri);
            return response;
        }