public async Task <PromotionBindingModel> GetPromotionBindingModelByAdIdAsync(int adId) { if (!await context.Ads.AnyAsync(x => x.Id == adId)) { throw new ArgumentException(GlobalConstants.InvalidAdIdErrorMessage); } var adFromDb = await adsService.GetAdByIdAsync(adId); var promotionViewModels = await context .Promotions .To <PromotionViewModel>() .ToListAsync(); var promotionBindingModel = new PromotionBindingModel { AdId = adFromDb.Id, AdTitle = adFromDb.Title, PromotionViewModels = promotionViewModels }; return(promotionBindingModel); }
public async Task <SendMessageViewModel> GetMessageViewModelByAdIdAsync(int adId) { if (!await context.Ads.AnyAsync(x => x.Id == adId)) { throw new ArgumentException(GlobalConstants.InvalidAdIdErrorMessage); } var ad = await adsService.GetAdByIdAsync(adId); var sendMessageViewModel = mapper.Map <SendMessageViewModel>(ad); sendMessageViewModel.SenderId = usersService.GetCurrentUserId(); return(sendMessageViewModel); }