Пример #1
0
        public IHttpActionResult PuttStuff(int id, tStuff tStuff)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public IHttpActionResult GettStuff(int id)
        {
            tStuff tStuff = db.tStuffs.Find(id);

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

            return(Ok(tStuff));
        }
Пример #3
0
        public IHttpActionResult PosttStuff(Models.Obj.CreateStuff.requestData requestData)
        {
            //Signaure string
            //FirstName  + LastName + Position

            var    authHeader = Request.Headers.Authorization;
            string authCode   = "";

            if (authHeader != null && authHeader.ToString().StartsWith("Basic"))
            {
                //Extract credentials
                authCode = authHeader.ToString().Replace("Basic ", "");
                //Check authcode
                if (authCode != "abcdefg01234567890")
                {
                    throw new Exception("The authorization header is not authorize");
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                tStuff tStuff = new tStuff();
                tStuff.FirstName  = requestData.FirstName;
                tStuff.LastName   = requestData.LastName;
                tStuff.JoinedDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                tStuff.Position   = requestData.Position;

                db.tStuffs.Add(tStuff);
                db.SaveChanges();

                var responseResult = new Models.Obj.CreateStuff.responseData();
                responseResult.FirstName  = tStuff.FirstName;
                responseResult.LastName   = tStuff.LastName;
                responseResult.ID         = tStuff.id;
                responseResult.JoinedData = tStuff.JoinedDate;
                responseResult.Position   = tStuff.Position;

                var encryptstring = responseResult.ID + responseResult.FirstName + responseResult.JoinedData;
                responseResult.signature = Utils.AesEncryption(encryptstring, WorkingKey);
                var testde = Utils.AesDecryption(responseResult.signature, WorkingKey);

                return(CreatedAtRoute("DefaultApi", new { id = tStuff.id }, responseResult));
            }
            else
            {
                //Handle what happens if that isn't the case
                throw new Exception("The authorization header is either empty or isn't Basic.");
            }
        }
Пример #4
0
        public IHttpActionResult DeletetStuff(int id)
        {
            tStuff tStuff = db.tStuffs.Find(id);

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

            db.tStuffs.Remove(tStuff);
            db.SaveChanges();

            return(Ok(tStuff));
        }