Exemplo n.º 1
0
 public HomeModule()
 {
     Get["/"] = _ => {
         List <Pet> allPets = Pet.GetAll();
         if (allPets.Count >= 0)
         {
             return(View["index.cshtml", allPets]);
         }
         else
         {
             return(View["index.cshtml"]);
         }
     };
     Post["/"] = _ => {
         Pet        newPet  = new Pet(Request.Form["new-pet"]);
         List <Pet> allPets = Pet.GetAll();
         return(View["index.cshtml", allPets]);
     };
     Post["/time"] = _ => {
         Pet.TimePass();
         List <Pet> allPets = Pet.GetAll();
         return(View["index.cshtml", allPets]);
     };
     Get["/pets/{id}"] = parameters => {
         Pet pet = Pet.Find(parameters.id);
         return(View["/pet.cshtml", pet]);
     };
     Post["/pets/{id}/food"] = parameters => {
         Pet pet = Pet.Find(parameters.id);
         pet.FeedPet();
         return(View["pet.cshtml", pet]);
     };
     Post["/pets/{id}/attention"] = parameters => {
         Pet pet = Pet.Find(parameters.id);
         pet.AttentionPet();//increase attention
         return(View["pet.cshtml", pet]);
     };
     Post["/pets/{id}/rest"] = parameters => {
         Pet pet = Pet.Find(parameters.id);
         pet.RestPet();//increase rest
         return(View["pet.cshtml", pet]);
     };
     Post["/clear"] = _ => {
         List <Pet> allPets = Pet.GetAll();
         Pet.ClearAll();
         return(View["index.cshtml", allPets]);
     };
 }
Exemplo n.º 2
0
 public HomeModule()
 {
     Get["/"]     = _ => View["index.cshtml"];
     Get["/pets"] = _ =>
     {
         List <Pet> allPets = Pet.GetAll();
         return(View["pets.cshtml", allPets]);
     };
     Post["/pets"] = _ =>
     {
         Pet        newPet  = new Pet(Request.Form["petName"], Request.Form["petType"]);
         List <Pet> allPets = Pet.GetAll();
         return(View["pets.cshtml", allPets]);
     };
     Get["/pet/{id}"] = parameters =>
     {
         Pet currentPet = Pet.Find(parameters.id);
         return(View["pet.cshtml", currentPet]);
     };
     Post["/{action}/{id}"] = parameters =>
     {
         Pet.PassTime();
         Pet currentPet = Pet.Find(parameters.id);
         if (parameters.action == "feed")
         {
             currentPet.SetFood(currentPet.GetFood() + 30);
             currentPet.SetLove(currentPet.GetLove() + 25);
         }
         else if (parameters.action == "love")
         {
             currentPet.SetLove(currentPet.GetLove() + 18);
             currentPet.SetRest(currentPet.GetRest() - 4);
         }
         else if (parameters.action == "rest")
         {
             currentPet.SetRest(currentPet.GetRest() + 60);
             currentPet.SetLove(currentPet.GetLove() + 30);
         }
         return(View["pet.cshtml", currentPet]);
     };
 }