// GET api/values/5 public ResponseSearchPet Get(string name = "", string typeSearch = "", string gender = "") { if (name == null) { name = ""; } if (typeSearch == null) { typeSearch = ""; } if (gender == null) { gender = ""; } ResponseSearchPet res = new ResponseSearchPet(); string csvFilePath = ConfigurationManager.AppSettings["CSVFilePath"].ToString(); Manager manager = new Manager(csvFilePath); RequestSearchPet request = new RequestSearchPet(); if (gender == "" && typeSearch == "" && gender == "") { res = manager.ReturnAllPets(); } if (gender != "") { switch (gender.ToUpper()) { case "M": request.SearchPetGender = "M"; break; case "F": request.SearchPetGender = "F"; break; case "MALE": request.SearchPetGender = "M"; break; case "FEMALE": request.SearchPetGender = "F"; break; default: throw new Exception("Only allowed values are MALE or FEMALE"); } } if (name != "") { request.SearchPetName = name.Trim(); } if (typeSearch != "") { request.SearchPetType = typeSearch.Trim().ToUpper(); } res = manager.SearchPet(request); return(res); }
public ResponseSearchPet SearchPet(RequestSearchPet request) { ResponseSearchPet response = new ResponseSearchPet(); request.SearchPetGender = (request.SearchPetGender == null) ? "" : request.SearchPetGender; request.SearchPetType = (request.SearchPetType == null) ? "" : request.SearchPetType; request.SearchPetName = (request.SearchPetName == null) ? "" : request.SearchPetName; response.results = DAManager.Search(request.SearchPetName, request.SearchPetType, request.SearchPetGender); return(response); }
static void Main(string[] args) { Parser.Default.ParseArguments <Options>(args) .WithParsed <Options>(o => { Console.WriteLine($"PROGRAM STARTED. Arguments: FileName:{o.FileName}"); Manager manager = new Manager(o.FileName); RequestSearchPet request = new RequestSearchPet(); request.SearchPetGender = o.GenderSearch; request.SearchPetName = o.NameSearch; request.SearchPetType = o.TypeSearch; if (request.SearchPetGender != null) { switch (request.SearchPetGender.ToUpper()) { case "MALE": request.SearchPetGender = "M"; break; case "FEMALE": request.SearchPetGender = "F"; break; default: throw new Exception("Only allowed values are MALE or FEMALE"); } } if (request.SearchPetName != null) { request.SearchPetName = request.SearchPetName.Trim(); } if (request.SearchPetType != null) { request.SearchPetType = request.SearchPetType.Trim().ToUpper(); } var resultSearch = manager.SearchPet(request); //draw a nice table here :) Console.WriteLine("Search Results:"); var table = new ConsoleTable(new string[] { "Animal Type", "Animal Name", "Gender", "Timestamp" }); //Animal Type, Animal Name, Gender, Timestamp foreach (var row in resultSearch.results) { table.AddRow(row.AnimalType, row.AnimalName, row.Gender, DateTime.ParseExact(row.LastUpdate, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture)); } table.Write(); Console.WriteLine("End of Search,That's all"); }); }
public void SearchPetTest() { Pets.Logic.Manager manager = new Manager(@"c:\pets\test.csv"); RequestNewPet requestNewPet = new RequestNewPet(); requestNewPet.AnimalName = "DANTELION"; requestNewPet.AnimalType = "DOG"; requestNewPet.Gender = "M"; bool success = manager.CreatePet(requestNewPet); RequestSearchPet request = new RequestSearchPet(); //request.SearchPetName = "DANTE"; //request.SearchPetType = "CAT"; request.SearchPetGender = "M"; var result = manager.SearchPet(request); Assert.IsNotNull(result); }