예제 #1
0
        public ActionResult Delete(int id)
        {
            MockData mockData = new MockData();

            try
            {
                MockDataContext mockDataContext = new MockDataContext();
                mockData = mockDataContext.MockDatas.Single(mock => mock.MockDataId == id);
                mockDataContext.Entry(mockData).State = EntityState.Deleted;
                mockDataContext.SaveChanges();

                return(Json(new { success = true, message = "Deleted Successfully!" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = "Error! " + ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public ActionResult AddUpdate(MockData mockData)
        {
            try
            {
                MockDataContext mockDataContext = new MockDataContext();

                if (mockData.MockDataId != 0)
                {
                    mockDataContext.MockDatas.Attach(mockData);
                    mockDataContext.Entry(mockData).State = EntityState.Modified;
                }
                else
                {
                    mockDataContext.MockDatas.Add(mockData);
                }

                mockDataContext.SaveChanges();

                return(Json(new { success = true, message = "Saved Successfully!" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex) {
                return(Json(new { success = false, message = "Error! " + ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }