public bool AddBook(BookAddModel bookAddModel) { var date = Convert.ToDateTime($"{bookAddModel.ReleaseDate}-01-01"); var owner = _booksDealersRepository.GetUserById(bookAddModel.OwnerId); var book = new Book { Owner = owner, Status = bookAddModel.Status, Title = bookAddModel.Title, Author = bookAddModel.Author, Category = bookAddModel.Category, ReleaseDate = date, CreationDate = DateTime.Now, Description = bookAddModel.Description, Isbn = bookAddModel.Isbn }; _booksDealersRepository.AddBook(book); return(_booksDealersRepository.Save()); }
public TradeViewModel mapDbTradeModelToViewTrade(Trade trade) { var initiator = _booksDealersRepository.GetUserById(trade.InitiatiorId); var initiatorUserData = new UserData { Id = initiator.Id, Name = initiator.Name }; var targetOwner = _booksDealersRepository.GetUserById(trade.TargetOwnerId); var targetOwnerUserData = new UserData { Id = targetOwner.Id, Name = targetOwner.Name }; var offer = _booksService.mapDbBookModelToViewBook(_booksDealersRepository.GetBook(trade.InitiatorOfferId)); var target = _booksService.mapDbBookModelToViewBook(_booksDealersRepository.GetBook(trade.TargetId)); var comments = (List <Comment>)trade.Comments; var commentsViewModel = new List <CommentViewModel>(); comments.ForEach(x => { commentsViewModel.Add(mapDbCommentModelToViewModel(x)); }); var tradeViewModel = new TradeViewModel { Id = trade.Id, Status = trade.Status, CreationDate = trade.CreationDate.ToString(), LastUpdated = trade.LastUpdated.ToString(), Initiator = initiatorUserData, TargetOwner = targetOwnerUserData, InitiatorOffer = offer, Target = target, Comments = commentsViewModel }; return(tradeViewModel); }
public UserCommonData GetUserData(int id) { var user = _booksDealersRepository.GetUserById(id); if (user != null) { return new UserCommonData { Id = user.Id, Name = user.Name, Email = user.Email } } ; return(null); } }