public ActionResult CreateSystemStatLevel([DataSourceRequest] DataSourceRequest request, SystemStatLevelVM viewModel)
        {
            try
            {
                if (viewModel != null && ModelState.IsValid)
                {
                    SystemStatLevel newviewModel = new SystemStatLevel();

                    newviewModel = Mapper.Map<SystemStatLevelVM, SystemStatLevel>(viewModel, newviewModel);

                    db.SystemStatLevels.Add(newviewModel);
                    db.SaveChanges();
                    viewModel.SystemStatLevelId = newviewModel.SystemStatLevelId;
                    viewModel.SystemStatName = db.SystemStats.Find(viewModel.SystemStatSystemStatId).Name;

                }
            }
            catch (DataException dataEx)
            {
                ModelState.AddModelError(string.Empty, "Could not add SystemStatLevel.");
                Elmah.ErrorSignal.FromCurrentContext().Raise(dataEx);
            }

            return Json(new[] { viewModel }.ToDataSourceResult(request, ModelState));
        }
 public ActionResult DestroySystemStatLevel([DataSourceRequest] DataSourceRequest request, SystemStatLevelVM viewModel)
 {
     try
     {
         if (viewModel != null)
         {
             ModelState.Clear();
             SystemStatLevel delviewModel = db.SystemStatLevels.Find(viewModel.SystemStatLevelId);
             if (delviewModel != null)
             {
                 db.SystemStatLevels.Remove(delviewModel);
                 db.SaveChanges();
             }
         }
     }
     catch (DbUpdateException dbUpdEx)
     {
         ModelState.AddModelError("showerror", "Delete failed.  This is most likely due to related child information that needs to be deleted first.");
         Elmah.ErrorSignal.FromCurrentContext().Raise(dbUpdEx);
     }
     catch (DataException dataEx)
     {
         ModelState.AddModelError("hideerror", "Could not delete SystemStatLevel.");
         Elmah.ErrorSignal.FromCurrentContext().Raise(dataEx);
     }
     return Json(ModelState.IsValid ? new object() : ModelState.ToDataSourceResult());
 }
 // SpringGage
 public JsonResult SystemStatLevelsListing([DataSourceRequest]DataSourceRequest request, bool AddDefault = false)
 {
     IQueryable<SystemStatLevel> tObj = null;
     tObj = db.SystemStatLevels.OrderBy(o => o.Level);
     List<SystemStatLevelVM> resultList = new List<SystemStatLevelVM>();
     SystemStatLevelVM firstItem = new SystemStatLevelVM();
     if (AddDefault)
     {
         firstItem.SystemStatLevelId = -1;
         firstItem.Level = 0;
         resultList.Add(firstItem);
     }
     foreach (var item in tObj)
     {
         SystemStatLevelVM newItem = new SystemStatLevelVM();
         newItem.SystemStatLevelId = item.SystemStatLevelId;
         newItem.Level = item.Level;
         resultList.Add(newItem);
     }
     return Json(resultList, JsonRequestBehavior.AllowGet);
 }