public async Task <IActionResult> GetById([FromHeader] GetByIdModel model) { try { if (this.ValidRoleForAction(_context, _auth, new string[] { "Admin" })) { if (ModelState.IsValid) { Faculty faculty = await _context.GetFaculty(model.Id.Value); if (faculty != null) { return(Ok(faculty)); } return(NotFound("Faculty not found")); } return(BadRequest("Model is not valid")); } return(Forbid()); } catch (Exception ex) { var arguments = this.GetBaseData(_context, _auth); _logger.LogException(ex, arguments.Email, arguments.Path); return(BadRequest($"{ex.GetType().Name} was thrown.")); } }
public async Task <IActionResult> Get([FromBody] GetByIdModel model) { try { if (this.ValidRoleForAction(_context, _auth, new string[] { "Student", "Teacher", "Editor", "Admin" })) { if (ModelState.IsValid) { Book book = await _context.GetBook(model.Id.Value); if (book != null) { BookViewModel viewModel = new BookViewModel(book); if (book.AppIdentityUser.UserType == "Student") { viewModel.GroupName = _context.GetUserGroup(book.AppIdentityUserId); return(Ok(viewModel)); } return(Ok(viewModel)); } return(NotFound("Book not found")); } return(BadRequest("Model is not valid")); } return(Forbid()); } catch (Exception ex) { var arguments = this.GetBaseData(_context, _auth); _logger.LogException(ex, arguments.Email, arguments.Path); return(BadRequest($"{ex.GetType().Name} was thrown.")); } }
public async Task <IActionResult> GetById([FromBody] GetByIdModel model) { try { if (this.ValidRoleForAction(_context, _auth, new string[] { "Admin" })) { if (ModelState.IsValid) { AppIdentityUser editor = await _auth.FindUserById(model.UserId); if (editor != null) { return(Ok(editor)); } return(NotFound("Editor not found")); } return(BadRequest("Model is not valid")); } return(Forbid()); } catch (Exception ex) { var arguments = this.GetBaseData(_context, _auth); _logger.LogException(ex, arguments.Email, arguments.Path); return(BadRequest($"{ex.GetType().Name} was thrown.")); } }