public ActionResult Post([FromBody] PetControllerRootPost payload) { // Check if payload is present if (payload == null) { return(BadRequest("PetController (POST) - Missing payload.")); } try { // Request user to be created var petIdentifier = _petService.CreatePet(payload); return(Ok(petIdentifier)); } catch (JsonSerializationException e) { // Return 422 if we can't parse the payload as JSON return(UnprocessableEntity(e.Message)); } catch (InvalidCastException e) { // Return 422 if we can't parse the user identifier as GUID return(UnprocessableEntity(e.Message)); } catch (InvalidOperationException e) { // Return 409 if the user already exists return(Conflict(e.Message)); } catch (Exception e) { // Return 500 if any other exception occurred return(Problem(e.Message, e.Source, 500, "UserController (POST)", e.GetType().ToString())); } }
public ActionResult CreateNewPet(CreatePetDTO newPet) { var pet = new Pet { Name = newPet.Name, PersonId = newPet.PersonId, DateOfBirth = newPet.DateOfBirth }; //pet.PetType = newPet.PetType; petService.CreatePet(pet); return(Ok()); }
public static void Main(string[] args) { var petRepo = new PetRepository(); petRepo.InitData(); PetService _petService = new PetService(petRepo); petList = petRepo.ReadPets(); var serviceCollection = new ServiceCollection(); serviceCollection.AddScoped <IPetRepository, PetRepository>(); serviceCollection.AddScoped <IPetService, PetService>(); serviceCollection.AddScoped <IPrinter, Printer>(); var serviceProvider = serviceCollection.BuildServiceProvider(); var printer = serviceProvider.GetRequiredService <IPrinter>(); var selection = printer.PrintMenuItems(); //int selection = printer.PrintMenuItems(); while (selection != 8) { switch (selection) { case 1: Console.Clear(); printer.PrintListOfPets(petList); break; case 2: Console.Clear(); printer.PrintListOfPets(_petService.GetPetsByType(printer.GetTypeFromUser())); break; case 3: Console.Clear(); Pet newPet = printer.CreatePet(); newPet.PetID = petList.Count + 1; _petService.CreatePet(newPet); break; case 4: Console.Clear(); _petService.DeleteByID(printer.GetIDFromUser()); break; case 5: Console.Clear(); _petService.UpdateByID(printer.GetIDFromUser(), printer.PrintUpdatePet()); break; case 6: Console.Clear(); printer.PrintByPrice(_petService.GetSortedList()); //DONE break; case 7: Console.Clear(); printer.PrintFiveCheapest(_petService.GetSortedFiveList()); //DONE break; default: Console.Clear(); break; } selection = printer.PrintMenuItems(); } printer.UserLeaving(); }
static void Main(string[] args) { FakeDB.InitData(); IPetRepository PR = new PetRepository(); IPetService PS = new PetService(PR); do { Console.WriteLine("Welcome to my little Pet shop"); Console.WriteLine("0. Exit"); Console.WriteLine("1. Show all pets"); Console.WriteLine("2. Search pets"); Console.WriteLine("3. Create new pet"); Console.WriteLine("4. Delete pet"); Console.WriteLine("5. Update pet"); Console.WriteLine("6. Sort pets by Price"); Console.WriteLine("7. Show 5 cheapest pets"); switch (Int32.Parse(Console.ReadLine())) { case 0: Run = false; break; case 1: foreach (var Pet in PS.GetPets()) { Console.WriteLine(Pet.ToString()); } break; case 2: foreach (var Pet in PS.GetPetsByType(Console.ReadLine())) { Console.WriteLine(Pet.ToString()); } break; case 3: PS.CreatePet(); break; case 4: PS.DeletePet(); break; case 5: Console.WriteLine("Please enter ID of a pet you want to update"); PS.UpdatePet(int.Parse(Console.ReadLine())); Console.WriteLine("Dont write anything if you dont want to update selected information"); break; case 6: PS.SortPetsByPrice(); break; case 7: foreach (var Pet in PS.GetFiveCheapest()) { Console.WriteLine(Pet.ToString()); } break; default: break; } } while (Run); }
// starts the UI public void StartUI() { string[] menuItems = { "List all pets", "Add pet", "Delete pet", "Edit pet", "Search by type", "Sort pets by price", "Get 5 cheapest pets", "Create Customer", "Delete Customer", "Edit Customer", "List all Customer", "Create Type", "Delete Type", "Edit Type", "List all Types", "Exit" }; var selection = ShowMenu(menuItems); while (selection != 16) { switch (selection) { case 1: var pets = _petService.GetPets(); ListPets(pets); break; case 2: var name = AskQuestion("What is the name of the pet? "); var previousOwner = AskQuestion("Who was the previous owner of the pet? "); var price = AskQuestion("What is the price of the pet? "); var soldDate = AskQuestion("When was the pet sold? "); var birthDate = AskQuestion("When was the pet born? "); var color = AskQuestion("What is the color of the pet? "); var pet = _petService.NewPet(name, previousOwner, Convert.ToDouble(price), Convert.ToDateTime(soldDate), Convert.ToDateTime(birthDate), color); _petService.CreatePet(pet); break; case 3: var idForDeletePet = PrintFindPetId(); _petService.DeletePet(idForDeletePet); break; case 4: var idForEdit = PrintFindPetId(); var petToEdit = _petService.FindPetById(idForEdit); Console.WriteLine("Updating " + petToEdit.Name); var newName = AskQuestion("What is the new name of pet? "); var newPreviousOwner = AskQuestion("Who was the previous Owner? "); var newPrice = AskQuestion("What is the new price of the pet? "); var newSoldDate = AskQuestion("When was it sold?"); var newBirthDate = AskQuestion("When was it born?"); var newColor = AskQuestion("What is the color of the pet?"); _petService.UpdatePet(new Pet() { ID = idForEdit, Name = newName, PreviousOwner = newPreviousOwner, Price = Convert.ToDouble(newPrice), SoldDate = Convert.ToDateTime(newBirthDate), BirthDate = Convert.ToDateTime(newBirthDate), Color = newColor }); break; case 5: var chosenType = AskQuestion("Insert type: "); var specifiedTypes = _typeService.getAllByType(chosenType); if (specifiedTypes != null) { ListTypes(specifiedTypes); } else { Console.WriteLine("No such type"); } break; case 6: var choice = AskQuestion("ASC or DESC: "); if (choice.Contains("ASC")) { ListPets(_petService.getASC()); } else { ListPets(_petService.getDESC()); } break; case 7: ListPets(_petService.getCheapest()); break; case 8: var firstName = AskQuestion("What is the first name of the customer? "); var lastName = AskQuestion("What is the last name of the customer? "); var birthDateOfCustomer = AskQuestion("What is the birthdate of the customer? "); var adress = AskQuestion("What is the adress of the customer? "); var newbirth = Convert.ToDateTime(birthDateOfCustomer); var customer = _customerService.NewCustomer(firstName, lastName, newbirth, adress); _customerService.CreateCustomer(customer); break; case 9: var idForDeleteCustomer = PrintFindCustomerId(); _customerService.DeleteCustomer(idForDeleteCustomer); break; case 10: var idForEditCustomer = PrintFindCustomerId(); var customerToEdit = _customerService.FindCustomerById(idForEditCustomer); Console.WriteLine("Updating " + customerToEdit.FirstName + customerToEdit.LastName); var newFirstName = AskQuestion("What is the new first name of customer? "); var newLastName = AskQuestion("What is the new last name of customer?"); var newBirthDateOfCustomer = AskQuestion("What is the new birthdate of customer? "); var newAdress = AskQuestion("What is the adress of the customer?"); _customerService.UpdateCustomer(new Customer() { ID = idForEditCustomer, FirstName = newFirstName, LastName = newLastName, BirthDateOfCustomer = Convert.ToDateTime(newBirthDateOfCustomer), Adress = newAdress, }); break; case 11: var customers = _customerService.GetCustomer(); ListCustomers(customers); break; case 12: var typetype = AskQuestion("What is the kind of pet? "); var TypeType = _typeService.NewType(typetype); _typeService.CreateType(TypeType); break; case 13: var idForDeleteType = PrintFindTypeId(); _typeService.DeleteType(idForDeleteType); break; case 14: var idForEditType = PrintFindTypeId(); var typeToEdit = _typeService.FindTypeById(idForEditType); Console.WriteLine("Updating " + typeToEdit); var newType = AskQuestion("What is the new name of the type of pet? "); _typeService.UpdateType(new Core.Type() { ID = idForEditType, TypeType = newType, }); break; case 15: var types = _typeService.GetTypes(); ListTypes(types); break; case 16: default: break; } selection = ShowMenu(menuItems); } Console.WriteLine("Have a blessed day. Bye and See you!"); Console.ReadLine(); }