public IHttpActionResult AddUser([FromBody] User user) { if (_usersManager.AddUser(user)) { return(Ok()); } return(InternalServerError()); }
public async Task <IActionResult> Register([FromBody] RegisterRequestInfo info) { try { await _usersManager.AddUser(info); return(Ok()); } catch (UserAlreadyRegisteredException ex) { return(BadRequest("User already exists")); } }
public static void SelectAction() { string name, title; bool quit = false; do { Console.Clear(); Console.WriteLine("Select action:" + Environment.NewLine + "1. Create user" + Environment.NewLine + "2. Delete user" + Environment.NewLine + "3. Reward user" + Environment.NewLine + "4. Remove award from user" + Environment.NewLine + "5. Show all users" + Environment.NewLine + "6. Add award" + Environment.NewLine + "7. Delete award" + Environment.NewLine + "8. Show all awards" + Environment.NewLine + "9. Quit" ); int.TryParse(Console.ReadLine(), out int selectedItem); switch (selectedItem) { case 1: Console.WriteLine("Enter name: "); name = Console.ReadLine(); int year = Input("Please enter year of birth:"); int month = Input("Please enter month of birth:"); int day = Input("Please enter year of birth:"); try { Console.WriteLine(UsersManager.AddUser(name, new DateTime(year, month, day)) ? "User has been created." : "User already exists."); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); break; case 2: Console.WriteLine("Enter name: "); name = Console.ReadLine(); Console.WriteLine(UsersManager.DeleteUser(name) ? "User has been deleted." : "User is not found."); Console.ReadKey(); break; case 3: Console.WriteLine("Enter name: "); name = Console.ReadLine(); Console.WriteLine("Enter title: "); title = Console.ReadLine(); Console.WriteLine(UsersAwardsManager.AddAwardToUser(name, title) ? "Award has been added to user." : "User or award are not found or user already has got the award."); Console.ReadKey(); break; case 4: Console.WriteLine("Enter name: "); name = Console.ReadLine(); Console.WriteLine("Enter title: "); title = Console.ReadLine(); Console.WriteLine(UsersAwardsManager.RemoveAwardFromUser(name, title) ? "Award has been deleted from user." : "User or award are not found or user has not got the award."); Console.ReadKey(); break; case 5: ShowAllUsersWithAwards(UsersManager.GetAllUsers(), UsersAwardsManager.GetAllList()); Console.ReadKey(); break; case 6: Console.WriteLine("Enter title: "); title = Console.ReadLine(); try { Console.WriteLine(AwardsManager.AddAward(title) ? "Award has been created." : "Award already exists."); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); break; case 7: Console.WriteLine("Enter title: "); title = Console.ReadLine(); Console.WriteLine(AwardsManager.DeleteAward(title) ? "Award has been deleted." : "Award is not found."); Console.ReadKey(); break; case 8: ShowAllAwards(AwardsManager.GetAllAwards()); Console.ReadKey(); break; case 9: quit = true; UsersManager.Save(); AwardsManager.Save(); UsersAwardsManager.Save(); break; default: break; } } while (!quit); }
public bool AddUser(User admin, User addedUser) { addedUser.PasswordHash = CalculateMd5Hash(addedUser.PasswordHash); return(admin.IsAdmin ? (_usersManager.AddUser(addedUser) != Guid.Empty) : false); }
public void AddUsed() { _usersManager.AddUser(ReadUserDataFromConsole()); System.Console.WriteLine("Пользователь успешно добавлен!"); }