public ActionResult RegisterNewAccount([FromBody] AccountRequest accountRequest) { if (accountRequest is null) { return(BadRequest()); } if (String.IsNullOrEmpty(accountRequest.Name) || String.IsNullOrEmpty(accountRequest.Password) || String.IsNullOrEmpty(accountRequest.AuthorizationLevel)) { return(BadRequest()); } if (!AuthorizationLevelService.IsInDB(accountRequest.AuthorizationLevel)) { return(BadRequest($"The required authorization level {accountRequest.AuthorizationLevel} is not defined. " + $"Add the level and try it again!")); } AccountService.Create(accountRequest.Name, accountRequest.Password, accountRequest.AuthorizationLevel); var justAdded = AccountService.Read(accountRequest.Name); return(Ok(Mapper.Map <AccountResponse>(justAdded))); }
public IActionResult TestGet() { AuthorizationLevelService.Create("Admin"); AuthorizationLevelService.Create("Librarian"); AuthorizationLevelService.Create("Client"); CategoryService.Create("Scifi"); CategoryService.Create("History"); CategoryService.Create("Politics"); CategoryService.Create("Humor"); AccountService.Create("Von Neumann", "0123456789abcdf", "Admin"); AccountService.Create("Guthenberg", "1415", "Librarian"); AccountService.Create("Marilyn Monroe", "12345", "Client"); AccountService.Create("Elvis Presley", "01114", "Client"); AccountService.Create("Michael Jackson", "11111", "Client"); BookService.CreateIfNotExist("Hector Servadac"); BookCategoryService.Create("Hector Servadac", "Scifi", "Guthenberg"); BookService.Create("Neuromancer"); BookCategoryService.Create("Neuromancer", "Scifi", "Guthenberg"); BookService.Create("Terminator"); BookCategoryService.Create("Terminator", "Scifi", "Guthenberg"); BookService.Create("Diplomacy"); BookCategoryService.Create("Diplomacy", "Politics", "Guthenberg"); BookService.Create("Before Crisis"); BookCategoryService.Create("Before Crisis", "History", "Guthenberg"); BorrowingService.Create("Hector Servadac", "Marilyn Monroe"); BorrowingService.Create("Terminator", "Marilyn Monroe"); BorrowingService.Create("Diplomacy", "Michael Jackson"); var borrowing = BorrowingService.ReadByTitle("Hector Servadac"); BorrowingService.Delete(borrowing); return(View("Login")); }