private void InitData() { Pet pet1 = new Pet { Name = "Brandy", Type = "Dog", Birthday = new DateTime(2011, 04, 22), SoldDate = new DateTime(2015, 12, 20), Color = "Brown", PreviousOwner = "From Animal Shelter", Price = 12 }; _petService.AddPet(pet1); Pet pet2 = new Pet { Name = "Hudini", Type = "Hamster", Birthday = new DateTime(2008, 04, 26), SoldDate = new DateTime(2008, 05, 13), Color = "White", PreviousOwner = "Johny Bravo", Price = 4 }; _petService.AddPet(pet2); Pet pet3 = new Pet { Name = "Betsy", Type = "Goat", Birthday = new DateTime(2013, 11, 20).Date, SoldDate = new DateTime(2018, 08, 18).Date, Color = "Black", PreviousOwner = "Attila Reiner", Price = 850 }; _petService.AddPet(pet3); Pet pet4 = new Pet { Name = "LitBoi", Type = "Phoenix", Birthday = new DateTime(2001, 09, 07).Date, SoldDate = new DateTime(2010, 12, 11).Date, Color = "fire", PreviousOwner = "Albus Percival Wulfrick Brian Dumbledore", Price = 1337 }; _petService.AddPet(pet4); }
private void AddPet() { var pet = _petService.GetPetInstance(); Console.WriteLine("Type Pet Name:"); pet.PetName = Console.ReadLine(); Console.WriteLine("Type Pet Color:"); pet.Colour = Console.ReadLine(); Console.WriteLine("Type Pet Type:"); pet.PetType = Console.ReadLine(); Console.WriteLine("Type Pet Previous Owner:"); //pet.PetPreviousOwner = Console.ReadLine(); Console.WriteLine("Type Pet Price:"); double price; while (!double.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("Please select a number between 20 - 50.000"); } pet.Price = price; var petAdded = _petService.AddPet(pet); if (petAdded.Id > 0) { Console.WriteLine("Pet Added"); } }
public void CreatePet() { Console.WriteLine("Enter the name of the pet: "); string name = Console.ReadLine(); Console.WriteLine("Enter the type of pet: "); string type = Console.ReadLine(); Console.WriteLine("Enter the birthdate of the pet: "); DateTime bdate = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine("Enter the date when the pet was sold: "); DateTime soldDate = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine("Enter the color of the pet: "); string color = Console.ReadLine(); Console.WriteLine("Enter the name of the previous owner: "); Owner prevOwner = NewOwner(); Console.WriteLine("Enter the price of the pet"); double price = Convert.ToDouble(Console.ReadLine()); service.AddPet(name, type, bdate, soldDate, color, prevOwner, price); }
private void AddPet() { var pet = _petService.GetPetInstance(); SetPetDetails(pet); _petService.AddPet(pet); }
//navigation menu public void StartPrinting() { string[] menuItems = { "List All Pets", "Search Pets By Type", "Add Pet", "Delete Pet", "Update Pet", "Sort Pets By Price", "5 Cheapest Pets", "Exit" }; var selection = ShowMenu(menuItems); while (selection != 8) { switch (selection) { case 1: ShowAllPets(_iPetService.GetPets()); break; case 2: ShowPetsWithType(); break; case 3: Pet Pet = CreatePet(1); _iPetService.AddPet(Pet); break; case 4: DeletePet(); break; case 5: UpdatePet(); break; case 6: SortPetsByPrice(); break; case 7: ShowFiveCheapestPets(); break; case 8: Environment.Exit(-1); break; } selection = ShowMenu(menuItems); } Console.ReadLine(); }
void CreatePet(string name, string type, DateTime birthday, DateTime soldDate, string color, string previousOwner, double price) { var petToCreate = _petService.NewPet(name, type, birthday, soldDate, color, previousOwner, price); if (_petService.AddPet(petToCreate) != null) { Console.WriteLine("The pet was succesfully created. \n"); } }
public ActionResult <Pet> Post([FromBody] Pet pet) { pet.ID = 0; if (string.IsNullOrEmpty(pet.Type)) { return(null); } return(_petService.AddPet(pet)); }
public IActionResult AddHospital(Pet pet) { if (pet == null) { return(BadRequest()); } var re = _IPetService.AddPet(pet); return(Ok(re)); }
public ActionResult <Pet> Post([FromBody] Pet pet) { try { return(Ok(_petService.AddPet(pet))); } catch (Exception e) { return(BadRequest(e.Message)); } }
private void CreatePet() { Pet newPet = ReadPet(); if (_service.AddPet(newPet) != null) { Console.WriteLine("Successfully added pet!"); } else { Console.WriteLine("Could not add pet."); } }
public ActionResult <Pet> AddPet([FromBody] Pet pet) { try { return(Ok(_petService.AddPet(pet))); } catch (InvalidDataException e) { return(BadRequest("Something went wrong with your request\n" + e.Message)); } catch (DataBaseException e) { return(StatusCode(500, e.Message)); } }
public ActionResult <Pet> CreatePet([FromBody] Pet pet) { try { Pet petToAdd = PetService.CreatePet(pet.Name, pet.Type, pet.Birthdate, pet.Color, pet.Price); petToAdd.SoldDate = pet.SoldDate; Pet addedPet; if (pet.Owner != null) { if (pet.Owner.ID <= 0) { return(BadRequest("Owner ID can't be zero or negative")); } Owner owner = OwnerService.GetOwnerByID(pet.Owner.ID); if (owner == null) { return(BadRequest("No owner with that ID found")); } petToAdd.Owner = owner; petToAdd.SoldDate = DateTime.Now; } if (pet.Type == null) { return(BadRequest("No pet type selected")); } addedPet = PetService.AddPet(petToAdd); if (addedPet == null) { return(StatusCode(500, "Error saving pet to Database")); } return(Created("", addedPet)); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } }
void AddNewPet() { int price, year, month, day; Type type = TypeSelection(); Console.Write($" Type the name of the {type}: "); string name = Console.ReadLine(); Console.WriteLine($" What color does {name} has?"); string color = Console.ReadLine(); Console.WriteLine($" How much {name} costs?"); int.TryParse(Console.ReadLine(), out price); Console.WriteLine($" When did {name} born?"); Console.WriteLine(" Year: "); int.TryParse(Console.ReadLine(), out year); Console.WriteLine(" Month: "); int.TryParse(Console.ReadLine(), out month); Console.WriteLine(" Day: "); int.TryParse(Console.ReadLine(), out day); DateTime birth = new DateTime(year, month, day); DateTime sold = DateTime.UtcNow; Pet p = new Pet() { ID = GetNextId(), Name = name, Color = color, BirthDate = birth, SoldDate = sold, Price = price }; _petServ.AddPet(p); Console.WriteLine($" You've added {name} to the database.\n\nPress Enter to continue..."); Console.ReadLine(); StartUI(); }
// Test Case: Add Pet private async Task AddPet() { Log.Information("PetController.AddPet()"); string data = @"{ ""name"": ""Mia"", ""nickName"": ""MiaMia"", ""petTypeId"": 3, ""personId"": """ + Program.personId + @""", ""createdate"": """ + DateTime.Now.ToString() + @"""}"; /*{ * "name": "Mia", * "nickName": "MiaMia", * "petTypeId": 3, * "personId": "FFE36941-51F5-4FC9-9FEC-F5429AD61E11", * "createdate": "2020-08-22T15:47:25" * }*/ for (Int32 iCnt = 1; iCnt <= intTestRunCount; iCnt++) { await _petService.AddPet("AddPet", data); } }
private void AddPet() { var pet = _petService.GetInstance(); Console.WriteLine("What is the name of the pet?"); pet.Name = Console.ReadLine(); Console.WriteLine("What type of pet is it?"); pet.Type = Console.ReadLine(); Console.WriteLine("What Color is the pet?"); pet.Color = Console.ReadLine(); Console.WriteLine("Who was the previous owner?"); //pet.PreviousOwner = Console.ReadLine(); //Console.WriteLine("What is the price of the pet?"); double price; while (!double.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("Price must be a number"); } pet.Price = price; _petService.AddPet(pet); Console.WriteLine("Pet has been added"); }
public IActionResult AddPet(PetRequest addAnimalRequest) { var obj = _petService.AddPet(addAnimalRequest); return(Ok(obj)); }
public void Post([FromBody] Pet pet) { _petService.AddPet(pet); }
public void StartUI() { string[] menuItems = { "List All Pet", "Add Pet", "Delete pet", "Edit pet", "Search Pets by Type ", "Sort pet by Price", "Get 5 cheapest pet", "Read Owner", "Add newOwner", "update owner", "Delete Owner", "Exit" }; var selection = ShowMenu(menuItems); while (selection != 12) { switch (selection) { case 1: var petss = _petService.GetAllPet(); ListPet(petss); break; case 2: Pet pet = new Pet(); pet.Name = AskQuestion("pet name: "); Console.WriteLine("owner option out of work"); pet.PreviousOwner = getSelectOwner(); //for (int p = 0; p < _ownerService.GetAllOwner().Count; p++) //{ // foreach (var owner in _ownerService.GetAllOwner()) // { // Console.WriteLine(p + " " + owner.Firstname + " " + owner.LastName); // } //} int i; while (!int.TryParse(AskQuestion("Price: "), out i) || 0 > i) { Console.WriteLine("Try again it need to be a number above 0"); } pet.Price = i; int year, month, day; while (!int.TryParse(AskQuestion("Year it is born: "), out year) || 0 > year || year > DateTime.Today.Year) { Console.WriteLine("Try again it need to be a Year above 0, and before " + DateTime.Today.Year); } while (!int.TryParse(AskQuestion("month it is born: "), out month) || 0 > month || month > 12) { Console.WriteLine("Try again it need to be a month above 0, and before " + 12); } while (!int.TryParse(AskQuestion("day it is born: "), out day) || 0 > day || day > 31) { Console.WriteLine("Try again it need to be a day above 0, and before " + 31); } pet.Birthdate = new DateTime(year, month, day); pet.Color = AskQuestion("Color : "); while (!int.TryParse(AskQuestion("Year it is Sold: "), out year) || 0 > year || year > DateTime.Today.Year) { Console.WriteLine("Try again it need to be a Year above 0, and before " + DateTime.Today.Year); } while (!int.TryParse(AskQuestion("month it is Sold: "), out month) || 0 > month || month > 12) { Console.WriteLine("Try again it need to be a month above 0, and before " + 12); } while (!int.TryParse(AskQuestion("day it is Sold: "), out day) || 0 > day || day > 31) { Console.WriteLine("Try again it need to be a day above 0, and before " + 31); } pet.SoldDate = new DateTime(year, month, day); pet.Type = AskQuestion("What type of animal"); var pets = _petService.AddPet(pet); break; case 3: var idForDelete = PrintFindCustomeryId(); _petService.DeletePet(idForDelete); break; case 4: var idForEdit = PrintFindCustomeryId(); var petToEdit = _petService.FindPetById(idForEdit); Console.WriteLine("Updating " + petToEdit.Name + " Price:" + petToEdit.Price); petToEdit.Name = AskQuestion("Name: "); int k; while (!int.TryParse(AskQuestion("Price: "), out k) || 0 > k) { Console.WriteLine("Try again it need to be a number above 0"); } petToEdit.Price = k; _petService.UpdatePet(petToEdit); break; case 5: var type = AskQuestion("What type of animal"); List <Pet> petByType = petByTypeList(type); ListPet(petByType); break; case 6: var petsss = _petService.GetAllPet(); SortedListByPrice(petsss); ListPet(petsss); break; case 7: var pes = _petService.GetAllPet(); SortedListByPrice(pes); for (int p = 0; p < pes.Count && p < 5; p++) { Console.WriteLine($"Id: {pes[p].ID} Name: {pes[p].Name} " + " PreviousOwner: " + $"{pes[p].PreviousOwner.Firstname} {pes[p].PreviousOwner.LastName} " + $"Price: {pes[p].Price}\nBirthdate: {pes[p].Birthdate} SoldDate: {pes[p].SoldDate} Type: {pes[p].Type}\n"); } break; case 8: PrintOwner(_ownerService.GetAllOwner()); break; case 9: CreateNewOwner(); break; case 10: UpdateOwner(); break; case 11: PrintOwner(_ownerService.GetAllOwner()); var idForDeleteOwner = PrintFindCustomeryId(); _ownerService.DeleteOwner(idForDeleteOwner); break; default: break; } selection = ShowMenu(menuItems); } Console.WriteLine("Bye bye!"); Console.ReadLine(); }
public void AddPost([FromBody] Pets p) { _petService.AddPet(p); }
public void AddPet() { int selection; string name; PetType type; DateTime birthDate; DateTime soldDate; string color; string previousOwner; double price; Console.WriteLine("Input valid pet name\n"); name = Console.ReadLine(); string[] menuItems = { "Cat", "Dog", "Fish", "Goat", "Tiger", "Parrot", }; try { selection = ShowMenu(menuItems, MenuTypes.PetTypes); } catch (InvalidDataException e) { Console.WriteLine("Something went wrong with menuTypes\n" + e); selection = menuItems.Length; } switch (selection) { case 1: type = PetType.Cat; break; case 2: type = PetType.Dog; break; case 3: type = PetType.Fish; break; case 4: type = PetType.Goat; break; case 5: type = PetType.Parrot; break; case 6: type = PetType.Tiger; break; default: type = PetType.Kakorot; break; } Console.WriteLine("Input valid birthdate for pet\n"); Console.WriteLine("Format is day/month/year\n"); while (!_parser.IsDateParsable(Console.ReadLine(), out birthDate)) { Console.WriteLine("Not a valid date, please try again"); } Console.WriteLine("Input valid solddate for pet\n"); Console.WriteLine("Format is day/month/year\n"); while (!_parser.IsDateParsable(Console.ReadLine(), out soldDate)) { Console.WriteLine("Not a valid date, please try again"); } Console.WriteLine("Input at valid color for pet\n"); color = Console.ReadLine(); Console.WriteLine("Input at valid previous owner for pet\n"); previousOwner = Console.ReadLine(); Console.WriteLine("Input a valid price for pet\n"); while (!_parser.IsDoubleParsable(Console.ReadLine(), out price)) { Console.WriteLine("Not a valid price, please try again"); } _petService.AddPet(name, type, birthDate, soldDate, color, previousOwner, price); }
public void CreatePet() { Console.Clear(); Console.WriteLine("Please enter the name of the pet"); string name = Console.ReadLine(); Console.Clear(); Console.WriteLine("Please enter the species of the pet"); string type = Console.ReadLine(); DateTime birthday = DateTime.MinValue; bool canParseDate = false; while (!canParseDate) { Console.Clear(); Console.WriteLine("Please enter the birthday of the pet \n" + "This most be done in the format of 01/12/2009 meaning the first of december 2009"); try { birthday = DateTime.Parse(Console.ReadLine()); canParseDate = true; } catch (Exception) { canParseDate = false; Console.WriteLine("You wrote in the wrong format, or a date that does not exist, please try again \n" + "Press enter to continue"); Console.ReadLine(); } } DateTime saleday = DateTime.MinValue; canParseDate = false; while (!canParseDate) { Console.Clear(); Console.WriteLine("Please enter the last sale day of the pet \n" + "This most be done in the format of 01/12/2009 meaning the first of december 2009"); try { saleday = DateTime.Parse(Console.ReadLine()); canParseDate = true; } catch (Exception) { canParseDate = false; Console.WriteLine("You wrote in the wrong format, or a date that does not exist, please try again \n" + "Press enter to continue"); Console.ReadLine(); } } Console.Clear(); Console.WriteLine("Please enter the color of the pet"); string color = Console.ReadLine(); Console.Clear(); Console.WriteLine("Please enter the name of the previous owner"); string previousOwner = Console.ReadLine(); Console.Clear(); double price; Console.WriteLine("Please enter the price of the pet in a number, you may use decimals"); while (!double.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("Enter a number dum dum"); } Pet thePet = new Pet() { BirthDate = birthday, Color = color, ID = 0, Name = name, PreviousOwner = previousOwner, Price = price, SoldDate = saleday, Type = type }; ps.AddPet(thePet); }
public void RegistraMascota(Pet pet) { _service.AddPet(pet); }