예제 #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
예제 #2
0
        public HttpResponseMessage PutProject(int id, Project project)
        {
            var db = ServicesContext.Current;

            logger.Info("PutProject called with id: " + id);

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != project.Id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            var dbx     = new ServicesContext(); //stupid that we have to do this.  maybe i'm stupid and there is a better way?! //TODO (we get ObjectStateManager error if we lookup and then change a project by id)
            var ownerid = dbx.Projects.Where(o => o.Id == id).FirstOrDefault().OwnerId;

            dbx.Dispose();

            //handle copying the ownerid from the existing project.
            project.OwnerId = ownerid;
            logger.Debug("PUT with owner id = " + ownerid + " for project " + project.Id);

            db.Entry(project).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }