public ActionResult <UserReadDto> GetUserById(int id) { var userItem = _repo.GetUserById(id); if (userItem == null) { return(NotFound()); } return(Ok(_mapper.Map <UserReadDto>(userItem))); }
public ActionResult <TransactionReadDto> AddTransaction(TransactionAddDto transactionAddDto) { Book book = _repo.GetBookById(transactionAddDto.BookId); if (book == null) { return(NotFound()); } if (book.IsAvaible == false) { return(Forbid()); } var usrId = Int32.Parse(User.Claims.First(p => p.Type == "id").Value); if (book.UserId == usrId) { return(Forbid()); } var transactionModel = _mapper.Map <Transaction>(transactionAddDto); transactionModel.DateTimeStart = DateTime.Now; transactionModel.DateTimeEnd = DateTime.Now.AddDays(transactionAddDto.DaysOfRentalTime); transactionModel.Status = TransactionStatus.Pending; transactionModel.RoomId = Guid.NewGuid().ToString(); transactionModel.CustomerId = Int32.Parse(User.Claims.First(p => p.Type == "id").Value); _repo.AddTransaction(transactionModel); book.IsAvaible = false; _repo.SaveChanges(); var tReadDto = _mapper.Map <TransactionReadDto>(transactionModel); tReadDto.Customer = _repo.GetUserById(usrId); return(Ok(tReadDto)); }