public JsonResult Delete([DataSourceRequest] DataSourceRequest request, GameQuestionDTO gameQuestionDTO) { try { //check to ensure the user owns the resources she is trying to access. if not; we get out of here. //Somebody is trying to do bad stuff. if (!ProbeValidate.IsGameQuestionForLoggedInUser(gameQuestionDTO.Id)) { ModelState.AddModelError("", "The attempt to remove a game question was not successful"); return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult())); } GameQuestion gameQuestion = db.GameQuestion.Find(gameQuestionDTO.Id); db.GameQuestion.Remove(gameQuestion); db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null); //Now that the gamequestion record is gone, get rid of the "UsedInGame" question/choice records ProbeQuestion.DeleteQuestion(this, db, gameQuestion.QuestionId); return(Json(new[] { gameQuestionDTO }.ToDataSourceResult(request, ModelState))); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR); return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult())); } }//public JsonResult DeleteGameQuestion([DataSourceRequest] DataSourceRequest request, GameQuestionDTO gameQuestionDTO)
public JsonResult Create([DataSourceRequest] DataSourceRequest request, GameQuestionDTO gameQuestionDTO) { try { //check to ensure the user owns the resources she is trying to access. if not; we get out of here. //Somebody is trying to do bad stuff. if (!ProbeValidate.IsGameForLoggedInUser((long)gameQuestionDTO.GameId)) { ModelState.AddModelError("", "The attempt to add a game question was not successful"); return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult())); } if (!ProbeValidate.IsQuestionForLoggedInUser((long)gameQuestionDTO.QuestionId)) { ModelState.AddModelError("", "The attempt to add a game question was not successful"); return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult())); } //transform DTO to business object (GameQuestion) GameQuestion gameQuestion = new GameQuestion { Id = 0, GameId = gameQuestionDTO.GameId, QuestionId = gameQuestionDTO.QuestionId, OrderNbr = gameQuestionDTO.OrderNbr, Weight = gameQuestionDTO.Weight }; //We need to clone the question and set the UsedInGame field to true. The cloned questions //is what will be associated with the game ChoiceQuestion clonedQuestion = ProbeQuestion.CloneQuestion(this, ref db, true, gameQuestion.QuestionId); gameQuestion.Question = clonedQuestion; //we do a switch to the cloned question db.GameQuestion.Add(gameQuestion); db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null); gameQuestionDTO.Id = gameQuestion.Id; //pass back the new Id to the client return(Json(new[] { gameQuestionDTO }.ToDataSourceResult(request, ModelState))); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR); return(Json(ModelState.IsValid ? true : ModelState.ToDataSourceResult())); } }
public ActionResult Update([DataSourceRequest] DataSourceRequest dsRequest, GameQuestionDTO gameQuestionDTO) { try { //we are only updating the Game Question order number and weight GameQuestion gameQuestion = db.GameQuestion.Find(gameQuestionDTO.Id); gameQuestion.OrderNbr = gameQuestionDTO.OrderNbr; gameQuestion.Weight = gameQuestionDTO.Weight; db.Entry(gameQuestion).State = EntityState.Modified; db.SaveChanges(Request != null ? Request.LogonUserIdentity.Name : null); return(Json(new[] { gameQuestionDTO }.ToDataSourceResult(dsRequest, ModelState))); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); //log to elmah ModelState.AddModelError("", ProbeConstants.MSG_UnsuccessfulOperation_STR); return(Json(ModelState.ToDataSourceResult())); } }