コード例 #1
0
        public IHttpActionResult PostPaRequestNotes(PaRequestNote paRequestNote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var headers = Request.Headers;

            if (headers.Contains("token"))
            {
                var userToken = headers.GetValues("token").First();

                string userName = JwtTokenHelper.GetTokenPayloadValue(userToken, "unique_name");
                paRequestNote.Created        = DateTime.Now;
                paRequestNote.CreatedBy      = userName;
                paRequestNote.LastModified   = DateTime.Now;
                paRequestNote.LastModifiedBy = userName;

                db.PaRequestNotes.Add(paRequestNote);
                db.SaveChanges();
            }

            return(CreatedAtRoute("DefaultApi", new { id = paRequestNote.Id }, paRequestNote));
        }
コード例 #2
0
        public IHttpActionResult GetPaRequestNotes(int id)
        {
            PaRequestNote paRequestNote = db.PaRequestNotes.Find(id);

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

            return(Ok(paRequestNote));
        }
コード例 #3
0
        public IHttpActionResult PutPaRequestNote(int id, PaRequestNote paRequestNote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != paRequestNote.Id)
            {
                return(BadRequest());
            }
            var headers = Request.Headers;

            if (headers.Contains("token"))
            {
                var userToken = headers.GetValues("token").First();

                string userName = JwtTokenHelper.GetTokenPayloadValue(userToken, "unique_name");
                string userRole = JwtTokenHelper.GetTokenPayloadValue(userToken, "role");

                if (userRole != "Administrator") //Need to check that the userName is the same as the created by
                {
                    if (userName != paRequestNote.CreatedBy)
                    {
                        return(BadRequest("Editing user is not an Administrator or did not create the original note."));
                    }
                }
                // paRequest.CompletedTimeStamp = DateTime.Now;
                paRequestNote.LastModified   = DateTime.Now;
                paRequestNote.LastModifiedBy = userName;

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        public IHttpActionResult DeletePaRequestNote(int id)
        {
            PaRequestNote paRequestNote = db.PaRequestNotes.Find(id);

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

            db.PaRequestNotes.Remove(paRequestNote);
            db.SaveChanges();

            return(Ok(paRequestNote));
        }