Beispiel #1
0
        //[System.Web.Http.HttpPost]
        /// <summary>
        /// Register a passage event
        /// </summary>
        /// <param name="payload"></param>
        /// <param name="hash"></param>
        /// <returns></returns>
        public IHttpActionResult Post(string payload, string hash)
        {
            // Validate hash
            // TODO use nonce
            const String SALT        = "%8vvpAwg48cvlcRwfAiY%A4gEj"; // not very secure
            var          hashCompare = Crypto.GetHashString(SALT + payload);
            var          response    = string.Format("payload: [{0}], hash: [{1}], hashCompare: [{2}]", payload, hash, hashCompare);

            if (hashCompare.Equals(hash, StringComparison.CurrentCultureIgnoreCase))
            {
                // Map parameters to properties
                var passage = new Passage();
                switch (payload.ToUpper())
                {
                case "IN":
                    passage.Direction = Passage.DirectionType.IN;
                    break;

                case "OUT":
                    passage.Direction = Passage.DirectionType.OUT;
                    break;

                default:
                    break;
                }
                passage.Message = DateTime.Now.ToString();
                CatFlapData.Save(passage);
            }
            else
            {
                return(Unauthorized());
            }
            return(Ok("OK"));
        }
Beispiel #2
0
 public void Add_Dummy_Data()
 {
     for (int i = 0; i < 10; i++)
     {
         var passage = new Passage(Passage.DirectionType.IN);
         //passage.
         CatFlapData.Save(passage);
     }
 }