public async Task <IActionResult> Ban(string adId) { var ad = await advertisementService.GetByIdAsync(adId); if (ad == null) { return(RedirectToAction("All")); } await advertisementService.BanByIdAsync(ad.Id); var notificationText = $"Your ad has been banned by admin - '{ad.Name}'"; var actionLink = $"/User/Profile?id={ad.Id}"; var notificationToAdOwner = await notificationService.CreateNotificationAsync(notificationText, actionLink); await notificationService.AssignNotificationToUserAsync(notificationToAdOwner.Id, ad.UserId); notificationText = $"Ad in your wishlist has been banned by admin - '{ad.Name}'"; actionLink = $"/User/Wishlist"; var usersIds = await userAdWishlistService.GetAllUserIdsThatHaveAdInWishlistAsync(ad.Id); var notificationToAllUsersThatHaveAdInWishlist = await notificationService.CreateNotificationAsync(notificationText, actionLink); await notificationService.AssignNotificationToUsersAsync(notificationToAllUsersThatHaveAdInWishlist.Id, usersIds.ToList()); return(RedirectToAction("All")); }
private async Task NotifyAsync(ViewServiceModel comment, AdvertisementViewServiceModel ad) { var commentOwner = await userManager.FindByIdAsync(comment.UserId); var commentUserName = commentOwner.UserName; var adOwner = await userManager.FindByIdAsync(ad.UserId); var notificationActionLink = $"/Advertisement/Details?id={ad.Id}"; if (adOwner.Id != commentOwner.Id) { var notificationText = $"{commentUserName} commented on your Ad: '{comment.Text}'"; var notification = await notificationService.CreateNotificationAsync(notificationText, notificationActionLink); await notificationService.AssignNotificationToUserAsync(notification.Id, adOwner.Id); } var userIds = await userAdWishlistService.GetAllUserIdsThatHaveAdInWishlistAsync(ad.Id); var usersToGetNotification = userIds.Where(u => u != comment.UserId).ToList(); if (usersToGetNotification.Count != 0) { var notificationText = $"{commentUserName} commented on an Ad in your Wishlist: '{comment.Text}'"; var notification = await notificationService.CreateNotificationAsync(notificationText, notificationActionLink); await notificationService.AssignNotificationToUsersAsync(notification.Id, usersToGetNotification); } }
private async Task NotifyOnAdArchiveAsync(string adId) { var ad = await advertisementService.GetByIdAsync(adId); var adOwner = await userManager.FindByIdAsync(ad.UserId); var notificationText = $"One of your adds in Wishlist has been archived: {ad.Name}"; var notificationActionLink = "/User/Wishlist?page=1"; var userIds = await userAdWishlistService.GetAllUserIdsThatHaveAdInWishlistAsync(ad.Id); if (userIds.Count() != 0) { var notification = await notificationService.CreateNotificationAsync(notificationText, notificationActionLink); await notificationService.AssignNotificationToUsersAsync(notification.Id, userIds.ToList()); } }
public async Task <IActionResult> Approve(string reportId) { var report = await reportService.GetByIdAsync(reportId); var ad = await advertisementService.GetByIdAsync(report.ReportedAdvertisementId); var adOwner = await userManager.FindByIdAsync(report.ReportedUserId); var reportOwner = await userManager.FindByIdAsync(report.ReportingUserId); var success = await reportService.ApproveByIdAsync(report.Id); if (success) { var notificationText = $"Your report has been approved by admin for ad - '{ad.Name}'"; var actionLink = $"/Advertisement/Details?id={ad.Id}"; var notificationToReportOwner = await notificationService.CreateNotificationAsync(notificationText, actionLink); await notificationService.AssignNotificationToUserAsync(notificationToReportOwner.Id, reportOwner.Id); notificationText = $"Ad in your wishlist has been banned by admin - '{ad.Name}'"; actionLink = $"/User/Wishlist"; var usersIds = await userAdWishlistService.GetAllUserIdsThatHaveAdInWishlistAsync(ad.Id); var notificationToAllUsersThatHaveAdInWishlist = await notificationService.CreateNotificationAsync(notificationText, actionLink); await notificationService.AssignNotificationToUsersAsync(notificationToAllUsersThatHaveAdInWishlist.Id, usersIds.ToList()); notificationText = $"Your Ad has been reported and approved by admin - '{ad.Name}' is banned because of '{report.Description}'"; actionLink = $"/User/BannedAds"; var notificationToAdOwner = await notificationService.CreateNotificationAsync(notificationText, actionLink); await notificationService.AssignNotificationToUserAsync(notificationToAdOwner.Id, adOwner.Id); } return(RedirectToAction("All")); }
public async Task GetAllUserIdsThatHaveAdInWishlistAsync_WithAds_ShouldReturnCorrectly() { var advertisement = new AdvertisementCreateServiceModel() { Name = "OnePlus 7 Pro", Description = "cool phone for everyday use, excellent performance", Price = 800, Condition = ProductCondition.New, CategoryId = "Electronics", SubCategoryId = "Phone", TownId = "testTownId", Address = "str nqkoq", Number = "telefonce", UserId = "test" }; await adService.CreateAsync(advertisement); var ad = await context.Advertisements.FirstOrDefaultAsync(a => a.Name == "OnePlus 7 Pro"); var advertisementWishlist = new UserAdvertisementWishlist { UserId = "test", AdvertisementId = ad.Id, Advertisement = ad, }; await context.UsersAdvertisementsWishlist.AddAsync(advertisementWishlist); await context.SaveChangesAsync(); var expectedResult = 1; var userIds = await service.GetAllUserIdsThatHaveAdInWishlistAsync(ad.Id); var actualResult = userIds.Count(); Assert.AreEqual(expectedResult, actualResult); }