示例#1
0
        protected override Note PatchEntity(int key, Delta <Note> patch)
        {
            if (patch == null)
            {
                return(null);
            }
            System.Diagnostics.Debug.WriteLine("The key is: " + key);
            var noteToPatch = GetEntityByKey(key);

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

            //Prepare changed properties to send to all clients
            var list = patch.GetChangedPropertyNames().ToList();

            foreach (var changedProperty in list)
            {
                object changedPropertyValue;
                patch.TryGetPropertyValue(changedProperty, out changedPropertyValue);
                Hub.Clients.All.updatePatchedNote(noteToPatch.noteID, changedProperty, changedPropertyValue);
                System.Diagnostics.Debug.WriteLine("Note has been patched: " + noteToPatch.noteID + ", " + changedProperty + ", " + changedPropertyValue);
            }

            return(noteToPatch);
        }
示例#2
0
        public async Task <IHttpActionResult> PutNoteBody(int id, NoteBody noteBody)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NoteBodyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#3
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));
        }
        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 Feature PatchEntity(int key, Delta <Feature> patch)
        {
            if (patch == null)
            {
                return(null);
            }
            var featureToPatch = GetEntityByKey(key);

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

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

            patch.TryGetPropertyValue(changedProperty, out changedPropertyValue);

            Hub.Clients.All.updateDeploy(featureToPatch.feaID, changedProperty, changedPropertyValue);
            return(featureToPatch);
        }
示例#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);
        }