public RepositoryTests() { var optionsBuilder = new DbContextOptionsBuilder <PhoneContext>(); optionsBuilder.UseSqlServer (@"Server=(localdb)\mssqllocaldb;Database=PhoneAPI;Trusted_Connection=True;ConnectRetryCount=0"); var options = Options.Create <AppSettings>(new AppSettings { Secret = "ApplicationSecret1235" }); _userService = new UserService(options); _phoneBookUsersRespository = new PhoneBookUsersRepository(new PhoneContext(optionsBuilder.Options)); _userController = new UserController(_userService, _phoneBookUsersRespository); _phoneBookUser = new PhoneBookUser { FirstName = "Joe", Surname = "Bloggs", Number = "01821276323", HouseNameNumber = "124", Street = "Test Street", Postcode = "L12 1234" }; }
public IActionResult Put(int id, [FromBody] PhoneBookUser newPhoneBookUser) { var result = _phoneBookUsersRespository.UpdateUser(id, newPhoneBookUser); if (result) { return(Ok(@"User {id} was updated successfully")); } return(BadRequest("User was not created.")); }
public IActionResult Create([FromBody] PhoneBookUser newPhoneBookUser) { var result = _phoneBookUsersRespository.CreateUser(newPhoneBookUser); if (result != null) { return(Ok(result)); } return(BadRequest("User was not created.")); }
static void Main(string[] args) { PhoneBookUser dragan = new PhoneBookUser(1, "Dragan", 070555666); PhoneBookUser aleksandar = new PhoneBookUser(2, "Dragan", 078213455); PhoneBookUser michael = new PhoneBookUser(3, "Michael", 077432544); PhoneBookUser jordan = new PhoneBookUser(4, "Jordan", 075666477); PhoneBookUser elliot = new PhoneBookUser(5, "Elliot", 072333555); Dictionary <int, PhoneBookUser> phoneBook = new Dictionary <int, PhoneBookUser>(); phoneBook.Add(dragan.PersonNumber, dragan); phoneBook.Add(aleksandar.PersonNumber, aleksandar); phoneBook.Add(michael.PersonNumber, michael); phoneBook.Add(jordan.PersonNumber, jordan); phoneBook.Add(elliot.PersonNumber, elliot); Console.WriteLine("Enter the name: "); string userInput = Console.ReadLine(); string userInputSec = char.ToUpper(userInput[0]) + userInput.Substring(1); bool NoFoundName = false; foreach (KeyValuePair <int, PhoneBookUser> keyValue in phoneBook) { PhoneBookUser user = keyValue.Value; if (userInputSec == user.Name) { Console.WriteLine($"Phone number of the User {user.Name} is: {user.PhoneNumber}"); NoFoundName = true; } if (!NoFoundName) { Console.WriteLine("ERROR..Name like this is not found in the Dictionary"); Console.WriteLine("Try again"); //string userIput = Console.ReadLine(); //string userInputSec = char.ToUpper(userInput[0]) + userInput.Substring(1); //bool NoFoundName = false; } else { Console.WriteLine("Task is done!!"); } } Console.ReadLine(); }
static void Main(string[] args) { PhoneBookUser john = new PhoneBookUser(1, "John", 070632985); PhoneBookUser mike = new PhoneBookUser(2, "Mike", 065638782); PhoneBookUser jack = new PhoneBookUser(3, "Jack", 070222782); PhoneBookUser bill = new PhoneBookUser(4, "Bill", 073772772); PhoneBookUser villiam = new PhoneBookUser(5, "Villiam", 075687687); Dictionary <int, PhoneBookUser> phoneBook = new Dictionary <int, PhoneBookUser>(); phoneBook.Add(john.ID, john); phoneBook.Add(mike.ID, mike); phoneBook.Add(jack.ID, jack); phoneBook.Add(bill.ID, jack); phoneBook.Add(villiam.ID, villiam); //PhoneBookUser John = phoneBook[1]; //PhoneBookUser Mike = phoneBook[2]; //PhoneBookUser Jack = phoneBook[3]; //PhoneBookUser Bill = phoneBook[4]; //PhoneBookUser Villiam = phoneBook[5]; Console.WriteLine("Enter name"); string userImput = Console.ReadLine(); string userUpper = char.ToUpper(userImput[0]) + userImput.Substring(1).ToLower(); bool noName = false; foreach (KeyValuePair <int, PhoneBookUser> keyValue in phoneBook) { PhoneBookUser user = keyValue.Value; if (userUpper == user.Name) { Console.WriteLine($" The phone number of User {user.Name} is {user.PhoneNumber} "); noName = true; } } if (!noName) { Console.WriteLine("Error....no such name"); } Console.ReadLine(); }