public void Test_Equal_ReturnsTrueForSameName() { Remedy firstRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); Remedy secondRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); Assert.Equal(firstRemedy, secondRemedy); }
public void Test_Update_UpdatesRemedyInDatabase() { //Arrange Remedy testRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); testRemedy.Save(); string newName = "Physical"; string newDescription = "fun"; string newSideEffect = "drowsy"; string newImage = "image2"; int newCategoryId = 2; //Act testRemedy.Update(newName, newDescription, newSideEffect, newImage, newCategoryId); string result1 = testRemedy.GetName(); string result2 = testRemedy.GetDescription(); string result3 = testRemedy.GetSideEffect(); string result4 = testRemedy.GetImage(); int result5 = testRemedy.GetCategoryId(); //Assert Assert.Equal(newName, result1); Assert.Equal(newDescription, result2); Assert.Equal(newSideEffect, result3); Assert.Equal(newImage, result4); Assert.Equal(newCategoryId, result5); }
public void Test_AddRemedy_AddsRemedyToDisease() { //Arrange Disease testDisease = new Disease("cold", "running nose", "image1", 1); testDisease.Save(); Remedy testRemedy = new Remedy("lemon", "yellow sour fruit", "very sour", "image1", 1); testRemedy.Save(); Remedy testRemedy2 = new Remedy("orange", "yellow sour fruit", "kinda sweet", "image2", 1); testRemedy2.Save(); //Act testDisease.AddRemedy(testRemedy); testDisease.AddRemedy(testRemedy2); List <Remedy> result = testDisease.GetRemedy(); List <Remedy> testList = new List <Remedy> { testRemedy, testRemedy2 }; //Assert Assert.Equal(testList, result); }
public static List <Remedy> GetAll() { List <Remedy> allRemedys = new List <Remedy> { }; SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM remedies;", conn); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { int remedyId = rdr.GetInt32(0); string remedyName = rdr.GetString(1); string remedyDescription = rdr.GetString(2); string remedySideEffect = rdr.GetString(3); string remedyImage = rdr.GetString(4); int remedyCategoryId = rdr.GetInt32(5); Remedy newRemedy = new Remedy(remedyName, remedyDescription, remedySideEffect, remedyImage, remedyCategoryId, remedyId); allRemedys.Add(newRemedy); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(allRemedys); }
public void Test_Find_FindsRemedyInDatabase() { Remedy testRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); testRemedy.Save(); Remedy foundRemedy = Remedy.Find(testRemedy.GetId()); Assert.Equal(testRemedy, foundRemedy); }
public void Test_Save_AssignsIdToRemedy() { Remedy testRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); testRemedy.Save(); Remedy savedRemedy = Remedy.GetAll()[0]; int result = savedRemedy.GetId(); int testId = testRemedy.GetId(); Assert.Equal(testId, result); }
public void Test_Save_SavesRemedyToDatabase() { Remedy testRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); testRemedy.Save(); List <Remedy> result = Remedy.GetAll(); List <Remedy> testList = new List <Remedy> { testRemedy }; Assert.Equal(testList, result); }
public override bool Equals(System.Object otherRemedy) { if (!(otherRemedy is Remedy)) { return(false); } else { Remedy newRemedy = (Remedy)otherRemedy; bool idEquality = this.GetId() == newRemedy.GetId(); bool nameEquality = this.GetName() == newRemedy.GetName(); bool descriptionEquality = this.GetDescription() == newRemedy.GetDescription(); bool sideEffect = this.GetSideEffect() == newRemedy.GetSideEffect(); bool imageEquality = this.GetImage() == newRemedy.GetImage(); bool categoryIdEquality = this.GetCategoryId() == newRemedy.GetCategoryId(); return(idEquality && nameEquality && descriptionEquality && sideEffect && imageEquality && categoryIdEquality); } }
public void Delete_DeletesRemedyAssociationsFromDataBase_RemedyList() { Disease testDisease = new Disease("cold", "running nose", "image1", 1); testDisease.Save(); Remedy testRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); testRemedy.Save(); testRemedy.AddDisease(testDisease); testRemedy.Delete(); List <Remedy> result = testDisease.GetRemedy(); List <Remedy> test = new List <Remedy> { }; Assert.Equal(test, result); }
public void AddDisease_AddsDiseasesToRemedy_DiseaseList() { Remedy testRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); testRemedy.Save(); Disease testDisease = new Disease("cold", "running nose", "image1", 1); testDisease.Save(); testRemedy.AddDisease(testDisease); List <Disease> result = testRemedy.GetDisease(); List <Disease> testList = new List <Disease> { testDisease }; Assert.Equal(testList, result); }
public void AddRemedy(Remedy newRemedy) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO diseases_remedies (diseases_id, remedies_id) VALUES (@DiseaseId, @RemedyId);", conn); SqlParameter DiseaseIdParameter = new SqlParameter("@DiseaseId", this.GetId()); SqlParameter RemedyIdParameter = new SqlParameter("@RemedyId", newRemedy.GetId()); cmd.Parameters.Add(DiseaseIdParameter); cmd.Parameters.Add(RemedyIdParameter); cmd.ExecuteNonQuery(); if (conn != null) { conn.Close(); } }
public void Test_Search_SearchesRemedyInDatabase() { //Arrange Remedy testRemedy1 = new Remedy("Herbal", "descriptionHerbal", "death", "website.com/photoOfRemedy.jpg", 1); testRemedy1.Save(); Remedy testRemedy2 = new Remedy("Advil", "description", "not quite death", "website.com/photoOfRemedy.jpg", 1); testRemedy2.Save(); //Act List <Remedy> resultRemedyList = Remedy.SearchRemedy("death"); List <Remedy> testRemedyList = new List <Remedy> { testRemedy1, testRemedy2 }; //Assert Assert.Equal(resultRemedyList, testRemedyList); }
public static Remedy Find(int id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM remedies WHERE id = @RemedyId;", conn); SqlParameter remedyIdParameter = new SqlParameter(); remedyIdParameter.ParameterName = "@RemedyId"; remedyIdParameter.Value = id.ToString(); cmd.Parameters.Add(remedyIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); int foundRemedyId = 0; string foundRemedyName = null; string foundRemedyDescription = null; string foundRemedySideEffect = null; string foundRemedyImage = null; int foundRemedyCategoryId = 0; while (rdr.Read()) { foundRemedyId = rdr.GetInt32(0); foundRemedyName = rdr.GetString(1); foundRemedyDescription = rdr.GetString(2); foundRemedySideEffect = rdr.GetString(3); foundRemedyImage = rdr.GetString(4); foundRemedyCategoryId = rdr.GetInt32(5); } Remedy foundRemedy = new Remedy(foundRemedyName, foundRemedyDescription, foundRemedySideEffect, foundRemedyImage, foundRemedyCategoryId, foundRemedyId); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(foundRemedy); }
public List <Remedy> GetRemedy() { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT remedies.* FROM diseases JOIN diseases_remedies ON (diseases.id = diseases_remedies.diseases_id) JOIN remedies ON (diseases_remedies.remedies_id = remedies.id) WHERE diseases.id = @diseaseId;", conn); SqlParameter diseaseIdParam = new SqlParameter("@diseaseId", this.GetId().ToString()); cmd.Parameters.Add(diseaseIdParam); SqlDataReader rdr = cmd.ExecuteReader(); List <Remedy> remedies = new List <Remedy> { }; while (rdr.Read()) { int id = rdr.GetInt32(0); string name = rdr.GetString(1); string description = rdr.GetString(2); string side_effect = rdr.GetString(3); string image = rdr.GetString(4); int categories_id = rdr.GetInt32(5); Remedy newRemedy = new Remedy(name, description, side_effect, image, categories_id, id); remedies.Add(newRemedy); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(remedies); }
public void Test_GetRemedy_RetrieveAllRemedyWithinCategoryRemedy() { //Arrange CategoryRemedy testCategoryRemedy = new CategoryRemedy("Herbal"); testCategoryRemedy.Save(); Remedy firstRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", testCategoryRemedy.GetId()); firstRemedy.Save(); Remedy secondRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", testCategoryRemedy.GetId()); secondRemedy.Save(); //Act List <Remedy> testRemedyList = new List <Remedy> { firstRemedy, secondRemedy }; List <Remedy> resultRemedyList = testCategoryRemedy.GetRemedy(); //Assert Assert.Equal(testRemedyList, resultRemedyList); }
public void Delete_DeletesDiseaseAssociationsFromDatabase_DiseaseList() { //Arrange Disease testDisease = new Disease("cold", "running nose", "image1", 1); testDisease.Save(); Remedy testRemedy = new Remedy("orange", "yellow sour fruit", "kinda sweet", "image2", 1); testRemedy.Save(); //Act testDisease.AddRemedy(testRemedy); testDisease.Delete(); List <Disease> resultRemedyDisease = Disease.GetAll(); List <Disease> testRemedyDisease = new List <Disease> { }; //Assert Assert.Equal(testRemedyDisease, resultRemedyDisease); }
public static List <Remedy> SearchRemedy(string inputString) { List <Remedy> AllRemedy = new List <Remedy> { }; SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM remedies WHERE name LIKE @inputString OR description LIKE @inputString OR side_effect LIKE @inputString;", conn); SqlParameter searchRemedyPara = new SqlParameter("@inputString", "%" + inputString + "%"); cmd.Parameters.Add(searchRemedyPara); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { int id = rdr.GetInt32(0); string name = rdr.GetString(1); string description = rdr.GetString(2); string side_effect = rdr.GetString(3); string image = rdr.GetString(4); int category_id = rdr.GetInt32(5); Remedy foundRemedy = new Remedy(name, description, side_effect, image, category_id, id); AllRemedy.Add(foundRemedy); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(AllRemedy); }
public void Test_ReturnsAllDiseases_DiseaseList() { Remedy testRemedy = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", 1); testRemedy.Save(); Disease testDisease1 = new Disease("cold", "running nose", "image1", 1); testDisease1.Save(); Disease testDisease2 = new Disease("flu", "sick", "image1", 2); testDisease2.Save(); testRemedy.AddDisease(testDisease1); testRemedy.AddDisease(testDisease2); List <Disease> result = testRemedy.GetDisease(); List <Disease> testList = new List <Disease> { testDisease1, testDisease2 }; Assert.Equal(testList, result); }
public List <Remedy> GetRemedy() { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM remedies WHERE categories_id = @CategoryId;", conn); SqlParameter CategoryRemedyIdPara = new SqlParameter("@CategoryId", this.GetId()); cmd.Parameters.Add(CategoryRemedyIdPara); SqlDataReader rdr = cmd.ExecuteReader(); List <Remedy> AllRemedy = new List <Remedy> { }; while (rdr.Read()) { int remedyId = rdr.GetInt32(0); string remedyName = rdr.GetString(1); string remedyDescription = rdr.GetString(2); string remedySideEffect = rdr.GetString(3); string remedyImage = rdr.GetString(4); int remedyCategoryId = rdr.GetInt32(5); Remedy newRemedy = new Remedy(remedyName, remedyDescription, remedySideEffect, remedyImage, remedyCategoryId, remedyId); AllRemedy.Add(newRemedy); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(AllRemedy); }
public void Test_Delete_DeleteCategoryRemedyFromDatabase() { //Arrange string name1 = "Herbal"; CategoryRemedy testCategoryRemedy1 = new CategoryRemedy(name1); testCategoryRemedy1.Save(); string name2 = "Physical"; CategoryRemedy testCategoryRemedy2 = new CategoryRemedy(name2); testCategoryRemedy2.Save(); Remedy Remedy1 = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", testCategoryRemedy1.GetId()); Remedy1.Save(); Remedy Remedy2 = new Remedy("Herbal", "descriptionHerbal", "sideEffectHerbal", "website.com/photoOfRemedy.jpg", testCategoryRemedy2.GetId()); Remedy2.Save(); //Act testCategoryRemedy1.Delete(); List <CategoryRemedy> resultCategoryRemedy = CategoryRemedy.GetAll(); List <CategoryRemedy> testCategoryRemedy = new List <CategoryRemedy> { testCategoryRemedy2 }; List <Remedy> resultRemedy = Remedy.GetAll(); List <Remedy> RemedyList = new List <Remedy> { Remedy2 }; //Assert Assert.Equal(testCategoryRemedy, resultCategoryRemedy); Assert.Equal(RemedyList, resultRemedy); }
public void Dispose() { CategoryDisease.DeleteAll(); Remedy.DeleteAll(); Disease.DeleteAll(); }
public void Test_RemedyEmptyAtFirst() { int result = Remedy.GetAll().Count; Assert.Equal(0, result); }
public void Dispose() { CategoryRemedy.DeleteAll(); Remedy.DeleteAll(); }
public HomeModule() { Get["/"] = _ => { return(View["index.cshtml"]); }; Get["/ailments"] = _ => { List <Disease> AllAilments = Disease.GetAll(); return(View["ailments.cshtml", AllAilments]); }; Get["/remedies"] = _ => { List <Remedy> AllRemedies = Remedy.GetAll(); return(View["remedies.cshtml", AllRemedies]); }; Get["/admin"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/remedy"] = _ => { string name = Request.Form["remedy-name"]; string description = Request.Form["remedy-description"]; string side_effect = Request.Form["remedy-side-effect"]; string image = Request.Form["remedy-image"]; int category_id = int.Parse(Request.Form["remedy-category-id"]); Remedy newRemedy = new Remedy(name, description, side_effect, image, category_id); Console.WriteLine(newRemedy.GetImage()); newRemedy.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/disease"] = _ => { string name = Request.Form["disease-name"]; string symptom = Request.Form["disease-symptom"]; string image = Request.Form["disease-image"]; int category_id = int.Parse(Request.Form["disease-category-id"]); Disease newDisease = new Disease(name, symptom, image, category_id); newDisease.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/remedy/category"] = _ => { string name = Request.Form["remedy-category-name"]; CategoryRemedy newCategoryRemedy = new CategoryRemedy(name); newCategoryRemedy.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/disease/category"] = _ => { string name = Request.Form["disease-category-name"]; CategoryDisease newCategoryDisease = new CategoryDisease(name); newCategoryDisease.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Post["/admin/addRemediesToDisease"] = _ => { string disease_id = Request.Form["disease_id"]; Disease foundDisease = Disease.Find(int.Parse(disease_id)); string remedies = Request.Form["treatment"]; string[] remedyArray = remedies.Split(','); foreach (string remedy_id in remedyArray) { Remedy foundRemedy = Remedy.Find(int.Parse(remedy_id)); foundDisease.AddRemedy(foundRemedy); } Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/diseaseCategory/delete/{id}"] = parameters => { CategoryDisease category = CategoryDisease.Find(parameters.id); return(View["category_disease_delete.cshtml", category]); }; Delete["/admin/diseaseCategory/delete/{id}"] = parameters => { CategoryDisease chosenCategoryDisease = CategoryDisease.Find(parameters.id); chosenCategoryDisease.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/remedyCategory/delete/{id}"] = parameters => { CategoryRemedy category = CategoryRemedy.Find(parameters.id); return(View["category_remedy_delete.cshtml", category]); }; Delete["/admin/remedyCategory/delete/{id}"] = parameters => { CategoryRemedy chosenCategoryRemedy = CategoryRemedy.Find(parameters.id); chosenCategoryRemedy.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/remedy/delete/{id}"] = parameters => { Remedy chosen = Remedy.Find(parameters.id); return(View["remedy_delete.cshtml", chosen]); }; Delete["/admin/remedy/delete/{id}"] = parameters => { Remedy chosenRemedy = Remedy.Find(parameters.id); chosenRemedy.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/disease/delete/{id}"] = parameters => { Disease chosen = Disease.Find(parameters.id); return(View["disease_delete.cshtml", chosen]); }; Delete["/admin/disease/delete/{id}"] = parameters => { Disease chosenDisease = Disease.Find(parameters.id); chosenDisease.Delete(); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/diseaseCategory/edit/{id}"] = parameter => { CategoryDisease SelectedCategoryDisease = CategoryDisease.Find(parameter.id); return(View["edit_category_disease.cshtml", SelectedCategoryDisease]); }; Patch["/admin/diseaseCategory/edit/{id}"] = parameter => { CategoryDisease SelectedCategoryDisease = CategoryDisease.Find(parameter.id); SelectedCategoryDisease.Update(Request.Form["edit-name"]); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/remedyCategory/edit/{id}"] = parameter => { CategoryRemedy SelectedCategoryRemedy = CategoryRemedy.Find(parameter.id); return(View["edit_category_remedy.cshtml", SelectedCategoryRemedy]); }; Patch["/admin/remedyCategory/edit/{id}"] = parameter => { CategoryRemedy SelectedCategoryRemedy = CategoryRemedy.Find(parameter.id); SelectedCategoryRemedy.Update(Request.Form["edit-name"]); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/disease/edit/{id}"] = parameter => { Dictionary <string, object> model = new Dictionary <string, object>(); Disease SelectedDisease = Disease.Find(parameter.id); var AllCategoryDisease = CategoryDisease.GetAll(); model.Add("SelectedDisease", SelectedDisease); model.Add("AllCategoryDisease", AllCategoryDisease); return(View["edit_disease.cshtml", model]); }; Patch["/admin/disease/edit/{id}"] = parameter => { Disease SelectedDisease = Disease.Find(parameter.id); SelectedDisease.Update(Request.Form["edit-name"], Request.Form["edit-symptom"], Request.Form["edit-image"], Request.Form["edit-category-id"]); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/admin/remedy/edit/{id}"] = parameter => { Dictionary <string, object> model = new Dictionary <string, object>(); Remedy SelectedRemedy = Remedy.Find(parameter.id); var AllCategoryRemedy = CategoryRemedy.GetAll(); model.Add("SelectedRemedy", SelectedRemedy); model.Add("AllCategoryRemedy", AllCategoryRemedy); return(View["edit_remedy.cshtml", model]); }; Patch["/admin/remedy/edit/{id}"] = parameter => { Remedy SelectedRemedy = Remedy.Find(parameter.id); SelectedRemedy.Update(Request.Form["edit-name"], Request.Form["edit-description"], Request.Form["edit-sideEffect"], Request.Form["edit-image"], Request.Form["edit-category-id"]); Dictionary <string, object> model = new Dictionary <string, object>(); List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); List <Disease> AllAilments = Disease.GetAll(); List <Remedy> AllRemedies = Remedy.GetAll(); model.Add("AllCategoryDisease", AllCategoryDisease); model.Add("AllCategoryRemedy", AllCategoryRemedy); model.Add("AllDiseases", AllAilments); model.Add("AllRemedies", AllRemedies); return(View["admin.cshtml", model]); }; Get["/ailments"] = _ => { List <Disease> AllDiseases = Disease.GetAll(); return(View["ailments.cshtml", AllDiseases]); }; Get["/remedies"] = _ => { List <Remedy> AllRemedies = Remedy.GetAll(); return(View["remedies.cshtml", AllRemedies]); }; Get["/remedies/{id}"] = parameters => { Remedy foundRemedy = Remedy.Find(parameters.id); List <Disease> DiseaseList = foundRemedy.GetDisease(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("foundRemedy", foundRemedy); model.Add("DiseaseList", DiseaseList); return(View["remedy.cshtml", model]); }; Get["/ailments/{id}"] = parameters => { Disease foundDisease = Disease.Find(parameters.id); List <Remedy> RemedyList = foundDisease.GetRemedy(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("foundDisease", foundDisease); model.Add("remedyList", RemedyList); return(View["ailment.cshtml", model]); }; Get["/categoryRemedy"] = _ => { List <CategoryRemedy> AllCategoryRemedy = CategoryRemedy.GetAll(); return(View["categoryRemedy_all.cshtml", AllCategoryRemedy]); }; Get["/categoryRemedy/{id}"] = parameters => { CategoryRemedy foundCategoryRemedy = CategoryRemedy.Find(parameters.id); List <Remedy> RemedyList = foundCategoryRemedy.GetRemedy(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("foundCategoryRemedy", foundCategoryRemedy); model.Add("RemedyList", RemedyList); return(View["category_remedy.cshtml", model]); }; Get["/categoryDisease"] = _ => { List <CategoryDisease> AllCategoryDisease = CategoryDisease.GetAll(); return(View["categoryDisease_all.cshtml", AllCategoryDisease]); }; Get["/categoryDisease/{id}"] = parameters => { CategoryDisease foundCategoryDisease = CategoryDisease.Find(parameters.id); List <Disease> DiseaseList = foundCategoryDisease.GetDisease(); Dictionary <string, object> model = new Dictionary <string, object>(); model.Add("foundCategoryDisease", foundCategoryDisease); model.Add("DiseaseList", DiseaseList); return(View["category_disease.cshtml", model]); }; Get["/search"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); List <Remedy> remedies = new List <Remedy> { }; List <Disease> diseases = new List <Disease> { }; model.Add("remedies", remedies); model.Add("diseases", diseases); return(View["search.cshtml", model]); }; Post["/search"] = _ => { List <Remedy> remedies = new List <Remedy> { }; List <Disease> diseases = new List <Disease> { }; Dictionary <string, object> model = new Dictionary <string, object>(); string searchString = Request.Form["search-field"]; string category = Request.Form["category"]; if (category == "Remedy") { remedies = Remedy.SearchRemedy(searchString); } else if (category == "Disease") { diseases = Disease.SearchDisease(searchString); } model.Add("remedies", remedies); model.Add("diseases", diseases); return(View["search.cshtml", model]); }; }