public ActionResult EditorAjax(int id) { QualityOfLife qualityoflife = null; if (id > 0) { //find an existing qualityoflife from database qualityoflife = qualityoflifeRepository.Find(id); if (qualityoflife == null) { //throw an exception if id is provided but data does not exist in database return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Quality Of Life not found")); } if (qualityoflife.QualityOfLifeSubCategory != null) { qualityoflife.QualityOfLifeCategoryID = qualityoflife.QualityOfLifeSubCategory.QualityOfLifeCategoryID; } } else { //create a new instance if id is not provided qualityoflife = new QualityOfLife(); } //return the html of editor to display on popup return(Content(this.RenderPartialViewToString(Constants.PartialViews.CreateOrEdit, qualityoflife))); }
public ActionResult SaveAjax(QualityOfLife qualityoflife) { //id=0 means add operation, update operation otherwise bool isNew = qualityoflife.ID == 0; //validate data if (ModelState.IsValid) { try { //call repository function to save the data in database qualityoflifeRepository.InsertOrUpdate(qualityoflife); qualityoflifeRepository.Save(); //set status message if (isNew) { qualityoflife.SuccessMessage = "Quality Of Life has been added successfully"; } else { qualityoflife.SuccessMessage = "Quality Of Life has been updated successfully"; } } catch (CustomException ex) { qualityoflife.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); qualityoflife.ErrorMessage = Constants.Messages.UnhandelledError; } } else { foreach (var modelStateValue in ViewData.ModelState.Values) { foreach (var error in modelStateValue.Errors) { qualityoflife.ErrorMessage = error.ErrorMessage; break; } if (qualityoflife.ErrorMessage.IsNotNullOrEmpty()) { break; } } } //return the status message in json if (qualityoflife.ErrorMessage.IsNotNullOrEmpty()) { return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, qualityoflife) })); } else { return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, qualityoflife) })); } }
public ActionResult Index([DataSourceRequest(Prefix = "Grid")] DataSourceRequest dsRequest) { if (!ViewBag.HasAccessToAdminModule) { WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action"; return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty })); } QualityOfLife qualityoflife = new QualityOfLife(); return(View(qualityoflife)); }
public ActionResult DeleteAjax(int id) { if (!ViewBag.HasAccessToAdminModule) { BaseModel baseModel = new BaseModel(); baseModel.ErrorMessage = "You are not eligible to do this action"; return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, baseModel) }, JsonRequestBehavior.AllowGet)); } //find the qualityoflife in database QualityOfLife qualityoflife = qualityoflifeRepository.Find(id); if (qualityoflife == null) { //set error message if it does not exist in database qualityoflife = new QualityOfLife(); qualityoflife.ErrorMessage = "Quality Of Life not found"; } else { try { //delete qualityoflife from database qualityoflifeRepository.Delete(qualityoflife); qualityoflifeRepository.Save(); //set success message qualityoflife.SuccessMessage = "Quality Of Life has been deleted successfully"; } catch (CustomException ex) { qualityoflife.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); qualityoflife.ErrorMessage = Constants.Messages.UnhandelledError; } } //return action status in json to display on a message bar if (qualityoflife.ErrorMessage.IsNotNullOrEmpty()) { return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, qualityoflife) })); } else { return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, qualityoflife) })); } }
static void Main(string[] args) { //new classes QualityOfLife qol = new QualityOfLife(); Player player = new Player(); Zombie zombie = new ArmoredZombie(); // introduction text Console.WriteLine("Welcome to the Zombie Arena"); // controls whether battle should continue bool isBattleOver = false;; // battle loop while (!isBattleOver) { // prompt the player for input //put choices into array string[] choices = new string[7] { "help", "quit", "check health", "am I alive", "attack", "hide", "heal" }; string help = choices[0]; string checkHealth = choices[1]; string amAlive = choices[2]; string attack = choices[3]; string hide = choices[4]; string heal = choices[5]; string quit = choices[6]; Console.WriteLine("What would you like to do?"); Console.WriteLine("your choices are:"); Console.WriteLine(help);//do it later Console.WriteLine(quit); Console.WriteLine(checkHealth); Console.WriteLine(amAlive); Console.WriteLine(attack); Console.WriteLine(hide); Console.WriteLine(heal); //player turn string playerChoice = Console.ReadLine(); //help if (playerChoice == choices[0]) { Console.WriteLine(help + ": this is where you are now"); Console.WriteLine(quit + ": quit the game"); Console.WriteLine(checkHealth + ": seehow much health you have left"); Console.WriteLine(amAlive + ": see if your still alive"); Console.WriteLine(attack + ": hit the zombie"); Console.WriteLine(hide + ": hide from attacks"); Console.WriteLine(heal + ": lick your wounds and recover health, can only be done while hiding"); Console.ReadLine(); continue; } //quit else if (playerChoice == choices[1]) { break; } //check health else if (playerChoice == choices[2]) { Console.WriteLine($"you have {player.healthPoints} health left"); Console.ReadLine(); continue; } //am alive else if (playerChoice == choices[3]) { Console.WriteLine("you certinly hope so!"); Console.ReadLine(); continue; } //attack else if (playerChoice == choices[4])//attack { if (player.hiding) { Console.WriteLine("you burst from cover and attack the zombie"); player.hiding = false; } else { Console.WriteLine($"you move to attack the zombie, it takes {player.Attack()} damage"); } zombie.health -= player.Attack(); Console.ReadLine(); } //hide else if (playerChoice == choices[5] && !player.hiding) { player.Hide(); Console.WriteLine("you duck into cover to hide from the zombies attacks"); Console.ReadLine(); } //healing else if (playerChoice == choices[6]) { //make sure player is hiding first if (player.hiding) { player.healthPoints += 15; Console.WriteLine("you heal for 15 points"); } else { Console.WriteLine("healing out in the open isnt a good idea"); continue; } //make sure you dont go over max health if (player.healthPoints > 100) { player.healthPoints = 100; } Console.ReadLine(); } //for test purposes else if (playerChoice == "wait") { } //failsafe else { Console.WriteLine("Invalid input"); Console.ReadLine(); continue; } // win loss condition if (player.IsDefeated) { Console.WriteLine("You fall to the ground defeated, the world fading to black"); break; } if (zombie.IsDefeated) { Console.WriteLine("You stand victorious to live another day"); } Console.WriteLine("the zombie attacks you, you take 20 damage"); player.TakeDamage(zombie.Attack()); Console.ReadLine(); } // good-bye text Console.WriteLine("Thanks for playing! Press ENTER to exit."); Console.ReadLine(); return; }