コード例 #1
0
        public HttpResponseMessage Post(category newCategory)
        {
            if(ModelState.IsValid)
            {
                bool Ok = qDB.insertCategory(newCategory);

                if(Ok)
                {
                    return new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK
                    };
                }
            }

            return new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.NotFound,
                Content = new StringContent("Could not insert new category")
            };
        }
コード例 #2
0
        public bool insertCategory(category newCategory)
        {
            var category = new Category
            {
                categoryName = newCategory.categoryname
            };

            try
            {
                db.Categories.Add(category);
                db.SaveChanges();
            }
            catch(Exception e)
            {
                return false;
            }
            return true;
        }