public GigUser AddUser(string email, string firstname, string lastname) { if (usersStorage.Any() && usersStorage.Any(storedUser => storedUser.Email == email)) { throw new UserAlreadyExistsException("User with this email already exists"); } GigUser newUser = new GigUser(email, firstname, lastname, ++nextId); usersStorage.Add(newUser); return(newUser); }
public void AddUser(GigUser newUser) { if (usersStorage.Any() && usersStorage.Any(storedUser => storedUser.Email == newUser.Email)) { throw new UserAlreadyExistsException("User with this email already exists"); } if (usersStorage.Any() && usersStorage.Any(storedUser => storedUser.UserId == newUser.UserId)) { throw new UserAlreadyExistsException("User with this id already exists"); } usersStorage.Add(newUser); }
public Invitation bookTicket(int zone, GigUser user) { return(Zones[zone - 1].BookSeat(user.UserId)); }
static void Main(string[] args) { Console.WriteLine("Choose functions: \n 1 - execprions \n 2 - event creation and ticket buying (Scenario) \n "); switch (Console.ReadLine()) { case "1": Exceptions(); break; case "2": Scenario(); break; } void Scenario() { //Console.WriteLine("Choose functions: \n 1 - execprions \n 2 - event creation and ticket buying (Scenario) \n "); GigUser dima = new GigUser("*****@*****.**", "Dima", "Bub"); ExampleEventBuilder bldr = new ExampleEventBuilder(); Event dimaEv = bldr.getEvent(); dimaEv.printZones(); dima.buyTicket(dimaEv); dima.invitations(); dimaEv.printZones(); } void Exceptions() { Storage dataStorage = new Storage(); GigUser me = dataStorage.AddUser("*****@*****.**", "Dima", "Bub"); Console.WriteLine($"User {me} created\n"); dataStorage.WriteToConsole(); Console.WriteLine(); Console.WriteLine("Please enter data for new user \n"); // Valid File format email firstname lastname; try { GigUser newUser = new GigUser(readConsole: true); try { dataStorage.AddUser(newUser); } catch (UserAlreadyExistsException exists) { Console.WriteLine(exists); } } catch (System.IndexOutOfRangeException) { Console.WriteLine("Less than 3 arguments entered"); } Console.WriteLine("\nAll users:"); dataStorage.WriteToConsole(); } }