コード例 #1
0
        public Candy Get(Candy request)
        {
            if (request == null)
                throw new ArgumentNullException("request");

            var currentProfiler = Profiler.Current;

            if (request.Id != default(uint))
            {
                using (currentProfiler.Step(string.Format("Looking for candy with Id: {0}", request.Id)))
                {
                    var cacheKey = base.Request.PathInfo;

                    using (currentProfiler.Step("Doing cache lookup for candy"))
                    {
                        var cacheItem = Cache.Get<Candy>(cacheKey);

                        if (cacheItem != null)
                            return cacheItem;
                    }

                    using (currentProfiler.Step("Doing db lookup for candy"))
                    {
                        var candy = Db.GetById<Candy>(request.Id);

                        Cache.Add(cacheKey, candy);

                        return candy;
                    }
                }
            }

            throw new ArgumentException("No candy matching Id");
        }
コード例 #2
0
        public object Delete(Candy request)
        {
            Db.DeleteById<Candy>(request.Id);

            return new HttpResult(HttpStatusCode.OK);
        }
コード例 #3
0
        public Candy Post(Candy request)
        {
            if (request.Id != default(uint))
                throw new ArgumentException("Can not insert candy with existing id");

            Db.Insert(request);

            var id = Db.GetLastInsertId();

            request.Id = Convert.ToUInt16(id);

            return request;
        }
コード例 #4
0
        public object Put(Candy request)
        {
            Db.Save(request);

            return request;
        }
コード例 #5
0
 public void Options(Candy request)
 {
 }