コード例 #1
0
 // PUT api/macguffin/5
 public HttpResponseMessage Put(int id, MacGuffin value)
 {
     return WrapInTryCatch(() =>
     {
         value.MacGuffinId = id;
         if (MacGuffinDbContext.UpdateMacGuffin(value))
             return new HttpResponseMessage(HttpStatusCode.OK);
         else
             return new HttpResponseMessage(HttpStatusCode.NotFound);
     }); 
 }
コード例 #2
0
 // POST api/macguffin
 public HttpResponseMessage Post(MacGuffin value) 
 {
     return WrapInTryCatch(() =>
     {
         int id = MacGuffinDbContext.AddMacGuffin(value);
         if (id > 0)
             return new HttpResponseMessage(HttpStatusCode.Created);
         else
             return new HttpResponseMessage(HttpStatusCode.InternalServerError); 
     }); 
 }
コード例 #3
0
        public static bool UpdateMacGuffin(MacGuffin obj)
        {
            if (obj.MacGuffinId > 0)
            {
                if (_db.ContainsKey(obj.MacGuffinId))
                {
                    _db[obj.MacGuffinId] = obj;
                    return true;
                }
            }

            return false;
        }
コード例 #4
0
        public static int AddMacGuffin(MacGuffin obj)
        {
            //find highest id 
            int idMax = 0;
            foreach (var i in _db.Values)
            {
                if (i.MacGuffinId > idMax)
                    idMax = i.MacGuffinId;
            }

            obj.MacGuffinId = idMax + 1;
            _db.Add(obj.MacGuffinId, obj);
            return obj.MacGuffinId;
        }
コード例 #5
0
ファイル: MacGuffinTest.cs プロジェクト: jrkosinski/RestAPI
        public void AddMacGuffin()
        {
            var all = new List<MacGuffin>(MacGuffinDbContext.GetAllMacGuffins());

            Assert.IsNotNull(all);
            Assert.IsTrue(all.Count > 0, "No MacGuffins found.");

            string description = "new test objecct";
            var newObject = new MacGuffin() { DateCreated = DateTime.Now, Description = description };
            int id = MacGuffinDbContext.AddMacGuffin(newObject); 

            var item = MacGuffinDbContext.GetMacGuffin(id);

            Assert.IsNotNull(item);
            Assert.AreEqual(id, item.MacGuffinId);
            Assert.AreEqual(item.Description, description); 
        }