public ActionResult CreateSystemSkill([DataSourceRequest] DataSourceRequest request, SystemSkillVM viewModel) { try { if (viewModel != null && ModelState.IsValid) { SystemSkill newviewModel = new SystemSkill(); newviewModel = Mapper.Map<SystemSkillVM, SystemSkill>(viewModel, newviewModel); db.SystemSkills.Add(newviewModel); db.SaveChanges(); viewModel.SystemSkillId = newviewModel.SystemSkillId; viewModel.SystemSkillCategoryName = db.SystemSkillCategories.Find(viewModel.SystemSkillCategorySystemSkillCategoryId).Name; viewModel.SystemActionName = db.SystemActions.Find(viewModel.SystemActionSystemActionId).Name; viewModel.SystemStatName = db.SystemStats.Find(viewModel.SystemStatSystemStatId).Name; } } catch (DataException dataEx) { ModelState.AddModelError(string.Empty, "Could not add SystemSkill."); Elmah.ErrorSignal.FromCurrentContext().Raise(dataEx); } return Json(new[] { viewModel }.ToDataSourceResult(request, ModelState)); }
public ActionResult DestroySystemSkill([DataSourceRequest] DataSourceRequest request, SystemSkillVM viewModel) { try { if (viewModel != null) { ModelState.Clear(); SystemSkill delviewModel = db.SystemSkills.Find(viewModel.SystemSkillId); if (delviewModel != null) { db.SystemSkills.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 SystemSkill."); Elmah.ErrorSignal.FromCurrentContext().Raise(dataEx); } return Json(ModelState.IsValid ? new object() : ModelState.ToDataSourceResult()); }
// SpringGage public JsonResult SystemSkillsListing([DataSourceRequest]DataSourceRequest request, bool AddDefault = false) { IQueryable<SystemSkill> tObj = null; tObj = db.SystemSkills.OrderBy(o => o.Name); List<SystemSkillVM> resultList = new List<SystemSkillVM>(); SystemSkillVM firstItem = new SystemSkillVM(); if (AddDefault) { firstItem.SystemSkillId = -1; firstItem.Name = "None"; resultList.Add(firstItem); } foreach (var item in tObj) { SystemSkillVM newItem = new SystemSkillVM(); newItem.SystemSkillId = item.SystemSkillId; newItem.Name = item.Name; resultList.Add(newItem); } return Json(resultList, JsonRequestBehavior.AllowGet); }