public JsonResult DeleteStat(int id) { bool bReturn = false; string message = "failed"; EResStat myStat = _db.EResStats.Find(id); if (myStat != null) { EResStat deletedStat = _db.EResStats.Remove(myStat); if (deletedStat != null) { try { if (_db.SaveChanges() > 0) { bReturn = true; message = "success"; } } catch (Exception ex) { message = ex.Message; } } } return(Json(new { Success = bReturn, Message = message }, JsonRequestBehavior.AllowGet)); }
public JsonResult CreateStat(EResStatViewModel viewModel) { bool bReturn = false; string message = "failed"; // TODO: Add insert logic here EResStat newStat = new EResStat() { DatabaseID = viewModel.DatabaseID, Year = viewModel.Year, Month = viewModel.Month, Searches = viewModel.Searches, Downloads = viewModel.Downloads, LinkedTo = viewModel.LinkedTo, LinkedFrom = viewModel.LinkedFrom }; if (_db.EResStats.Add(newStat) != null) { if (_db.SaveChanges() > 0) { bReturn = true; message = "success"; } } return(Json(new { Success = bReturn, Message = message }, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateStat(EResStatViewModel viewModel) { bool bReturn = false; string message = "failed"; EResStat myStat = _db.EResStats.Find(viewModel.StatID); if (myStat != null) { myStat.DatabaseID = viewModel.DatabaseID; myStat.Year = viewModel.Year; myStat.Month = viewModel.Month; myStat.Searches = viewModel.Searches; myStat.Downloads = viewModel.Downloads; myStat.LinkedTo = viewModel.LinkedTo; myStat.LinkedFrom = viewModel.LinkedFrom; try { _db.SaveChanges(); bReturn = true; message = "success"; } catch (InvalidOperationException ex) { message = ex.Message; } } return(Json(new { Success = bReturn, Message = message }, JsonRequestBehavior.AllowGet)); }