Exemplo n.º 1
0
        public IHttpActionResult PuttblComment(int id, Comment tblComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblComment.comID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblCommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public void FeatureChange(int id)
        {
            var deployToPatch = db.Deploys.Find(id);

            db.Entry(deployToPatch).State = EntityState.Modified;
            db.SaveChanges();
            System.Diagnostics.Debug.WriteLine("FeatureChange(id = " + id + ")");
        }
        protected override Comment PatchEntity(int key, Delta <Comment> patch)
        {
            if (patch == null)
            {
                return(null);
            }
            var commentToPatch = GetEntityByKey(key);

            patch.Patch(commentToPatch);
            db.Entry(commentToPatch).State = EntityState.Modified;
            db.SaveChanges();

            var    changedProperty = patch.GetChangedPropertyNames().ToList()[0];
            object changedPropertyValue;

            patch.TryGetPropertyValue(changedProperty, out changedPropertyValue);

            Hub.Clients.All.updateDeploy(commentToPatch.comID, changedProperty, changedPropertyValue);
            return(commentToPatch);
        }
Exemplo n.º 4
0
 public HttpResponseMessage PatchDeploy(int id, Delta <Deploy> newDeploy)
 {
     using (dbMainEntities objContext = new dbMainEntities())
     {
         Deploy deploy = objContext.Deploys.SingleOrDefault(p => p.depID == id);
         if (deploy == null)
         {
             throw new HttpResponseException(HttpStatusCode.NotFound);
         }
         newDeploy.Patch(deploy);
         objContext.SaveChanges();
     }
     return(Request.CreateResponse(HttpStatusCode.NoContent));
 }
        // PUT: odata/Status(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <Status> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Status status = db.Status.Find(key);

            if (status == null)
            {
                return(NotFound());
            }

            patch.Put(status);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StatusExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(status));
        }
Exemplo n.º 6
0
        protected override Deploy PatchEntity(int key, Delta <Deploy> patch)
        {
            //Check if data is null
            if (patch == null)
            {
                return(null);
            }

            //Initialize deploy object, patch delta into list, and status object
            var    deployToPatch = GetEntityByKey(key);
            var    list          = patch.GetChangedPropertyNames().ToList();
            object status        = null;

            //Determine if status is being changed
            foreach (var prop in list)
            {
                //If the data includes the field 'statusID'
                if (prop == "statusID")
                {
                    //Instantiate the status object
                    patch.TryGetPropertyValue(prop, out status);
                    System.Diagnostics.Debug.WriteLine("Status was set to: " + status);
                }
            }

            //If the status has been changed to DEPLOYING and the end time field is NOT empty,
            //change the deploy objects end time to null, and add the depEndTime property and null
            //value to the list
            if (status != null)
            {
                //If status is set to QUEUED
                if (status.Equals(1))
                {
                    //If start time or end time are NOT null, change them both to null
                    if (deployToPatch.depStartTime != null || deployToPatch.depEndTime != null)
                    {
                        deployToPatch.depStartTime = null;
                        deployToPatch.depEndTime   = null;
                        list.Add("depStartTime" + null);
                        list.Add("depEndTime" + null);
                        System.Diagnostics.Debug.WriteLine("Reset the start and end time.");
                    }
                    //If smoke value does NOT equal "NOT READY", change it to NOT READY
                    if (deployToPatch.smokeID != 1)
                    {
                        deployToPatch.smokeID = 1;
                        list.Add("smokeID");
                        patch.TrySetPropertyValue("smokeID", 1);
                    }
                }
                //Else if the status is set to DEPLOYING
                else if (status.Equals(2))
                {
                    //If the end time is NOT null, change it to null
                    if (deployToPatch.depEndTime != null)
                    {
                        deployToPatch.depEndTime = null;
                        list.Add("depEndTime");
                        System.Diagnostics.Debug.WriteLine("Reset the end time.");
                    }
                    //If the smoke value does NOT equal "NOT READY", change it to NOT READY
                    if (deployToPatch.smokeID != 1)
                    {
                        deployToPatch.smokeID = 1;
                        list.Add("smokeID");
                        patch.TrySetPropertyValue("smokeID", 1);
                    }
                }
            }
            //Patch the deploy on the server-end
            patch.Patch(deployToPatch);
            db.Entry(deployToPatch).State = EntityState.Modified;
            db.SaveChanges();

            //Prepare changed properties to send to all clients
            foreach (var changedProperty in list)
            {
                object changedPropertyValue;
                patch.TryGetPropertyValue(changedProperty, out changedPropertyValue);
                Hub.Clients.All.updateDeploy(deployToPatch.depID, changedProperty, changedPropertyValue);
                System.Diagnostics.Debug.WriteLine("Deploy has been patched: " + deployToPatch.depID + ", " + changedProperty + ", " + changedPropertyValue);
            }

            return(deployToPatch);
        }