protected ActionResult Delete <T>(int?id, IOrmModel Item) where T : IOrmModel, new()
        {
            int?Pk = Item.PrimaryKey().Value ?? id;

            if (Pk != null && Pk > 0)
            {
                try {
                    var model = (IOrmModel) new T();
                    var item  = model.Get <T>((int)Pk);
                    try {
                        item.Delete();
                    } catch (Exception) {
                        return(new HttpStatusCodeResult(505, "Found but not deleted"));
                    }
                } catch (SqlException) {
                    return(new HttpStatusCodeResult(404, "Not Found"));
                } catch (Exception) {
                    return(new HttpStatusCodeResult(400, "Bad Request"));
                }

                return(new HttpStatusCodeResult(204, "No Content"));
            }
            else
            {
                return(new HttpStatusCodeResult(404, "Not Found"));
            }
        }
        protected JsonResult Update <T>(IOrmModel item)
        {
            int?Pk = item.PrimaryKey().Value;

            if (Pk != null && Pk > 0)
            {
                item.Update();
            }
            else
            {
                item.Create();
            }
            return(Json(item, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        protected void Put <T>(int id, IOrmModel model) where T : IOrmModel, new()
        {
            int?Pk = model.PrimaryKey().Value;

            model.Update();
        }