public async Task CreateAsync(ReportCreateServiceModel report) { var reportModel = new Report { ReportedUserId = report.ReportedUserId, ReportingUserId = report.ReportingUserId, ReportedAdvertisementId = report.ReportedAdvertisementId, Description = report.Description, IsArchived = false, ReportedOn = DateTime.UtcNow }; await context.Reports.AddAsync(reportModel); await context.SaveChangesAsync(); }
public async Task CreateAsync_WithValidData_ShouldCreateSuccessfully() { var report = new ReportCreateServiceModel() { Description = "cool report description", ReportedAdvertisementId = "test", ReportedUserId = "testUser", ReportingUserId = "test123", }; await service.CreateAsync(report); var actualCategoryCount = context.Reports.Count(); var expectedCategoryCount = 1; Assert.AreEqual(expectedCategoryCount, actualCategoryCount); }
public async Task <IActionResult> Create(CreateBindingModel input) { if (!ModelState.IsValid) { return(Redirect($"/Report/Create?adId={input.ReportedAdvertisementId}")); } var serviceModel = new ReportCreateServiceModel { Description = input.Description, ReportedAdvertisementId = input.ReportedAdvertisementId, ReportedUserId = input.ReportedUserId, ReportingUserId = input.ReportingUserId }; await reportService.CreateAsync(serviceModel); var reportingUser = await userManager.FindByIdAsync(input.ReportingUserId); var reportedAd = await advertisementService.GetByIdAsync(input.ReportedAdvertisementId); var notificationText = $"{reportingUser.UserName} reported one of your ads - {reportedAd.Name}. '{input.Description}'"; var actionLink = $"Advertisement/Details?id={reportedAd.Id}"; var notification = await notificationService.CreateNotificationAsync(notificationText, actionLink); await notificationService.AssignNotificationToUserAsync(notification.Id, input.ReportedUserId); notificationText = $"{reportingUser.UserName} reported an ad - {reportedAd.Name} because of '{input.Description}'"; actionLink = $"/Administration/Report/All"; var notificationToAdmin = await notificationService.CreateNotificationAsync(notificationText, actionLink); await notificationService.AssignNotificationToUserAsync(notificationToAdmin.Id, await userService.GetAdminIdAsync()); return(Redirect($"/Advertisement/Details?id={input.ReportedAdvertisementId}")); }