public async Task<ReportContract> PostAsync(ReportContract report) { try { var registrationReference = await ValidateAndReturnCurrentUserId(); var reportContract = await _repository.InsertReport(report, registrationReference); var photoContract = await _repository.GetPhoto(reportContract.ContentId); if (photoContract.Status == PhotoStatus.UnderReview) { await _notificationHandler.SendPushAsync(PushNotificationPlatform.Windows, "user:"******"Your photo has been placed under review.", photoContract.ThumbnailUrl, photoContract.Id); } return reportContract; } catch (DataLayerException ex) { _telemetryClient.TrackException(ex); if (ex.Error == DataLayerError.Unknown) { throw ServiceExceptions.UnknownInternalFailureException(ServiceExceptions.Source); } throw ServiceExceptions.DataLayerException(ex.Message); } }
/// <summary> /// Creates a <see cref="ReportDocument" /> from a <see cref="ReportContract" />. /// </summary> /// <returns>The <see cref="ReportDocument" />.</returns> public static ReportDocument CreateFromContract(ReportContract contract) { return new ReportDocument { Id = contract.Id, Active = contract.Active, ReporterUserId = contract.ReporterUserId, ReportReason = contract.ReportReason, CreatedDateTime = new DateDocument { Date = contract.CreatedDateTime } }; }
public async Task<ReportContract> PostAsync(ReportContract report) { try { var registrationReference = await ValidateAndReturnCurrentUserId(); return await _repository.InsertReport(report, registrationReference); } catch (DataLayerException ex) { _telemetryClient.TrackException(ex); if (ex.Error == DataLayerError.Unknown) { throw ServiceExceptions.UnknownInternalFailureException(ServiceExceptions.Source); } throw ServiceExceptions.DataLayerException(ex.Message); } }
/// <summary> /// Inserts a report into Report table. /// </summary> /// <param name="report">The report being inserted.</param> /// <param name="userRegistrationReference">Azure Mobile Service user id who is reporting it.</param> /// <returns>The inserted Report.</returns> public Task<ReportContract> InsertReport(ReportContract report, string userRegistrationReference) { return _repository.InsertReport(report, userRegistrationReference); }
/// <summary> /// Inserts a report into Report table. /// </summary> /// <param name="reportContract">The report being inserted.</param> /// <param name="userRegistrationReference">Azure Mobile Service user id who is reporting it.</param> /// <returns>The inserted Report.</returns> public async Task<ReportContract> InsertReport(ReportContract reportContract, string userRegistrationReference) { reportContract.Id = Guid.NewGuid().ToString(); reportContract.ReporterUserId = GetUserDocumentByRegistrationReference(userRegistrationReference).Id; reportContract.CreatedDateTime = DateTime.UtcNow; var reportDocument = ReportDocument.CreateFromContract(reportContract); switch (reportContract.ContentType) { case ContentType.Photo: var photoDocument = GetPhotoDocument(reportContract.ContentId); photoDocument.Reports.Add(reportDocument); if (photoDocument.Reports.Count >= _maxReportsPermitted) { photoDocument.Status = PhotoStatus.UnderReview; var user = GetUserDocumentByUserId(photoDocument.UserId); if (user.ProfilePhotoId == photoDocument.Id) { user.ProfilePhotoId = null; user.ProfilePhotoUrl = null; await UpdateUser(user.ToContract()); } } await ReplacePhotoDocument(photoDocument); break; case ContentType.Annotation: var annotationDocument = GetAnnotationDocument(reportContract.ContentId); annotationDocument.Report = reportDocument; await UpdateAnnotationDocument(annotationDocument); break; default: throw new DataLayerException(DataLayerError.Unknown, "Unknown report content type"); } return reportContract; }
/// <summary> /// Reports the photo as inappropriate. /// </summary> /// <param name="photo">The photo to report.</param> /// <param name="reportReason">The reason for the report.</param> public async Task ReportPhoto(Photo photo, ReportReason reportReason) { try { var reportContract = new ReportContract { ReportReason = reportReason, ContentId = photo.Id, ContentType = ContentType.Photo }; await _mobileServiceClient.InvokeApiAsync<ReportContract, ReportContract>("report", reportContract, HttpMethod.Post, null); } catch (Exception e) { throw new ServiceException("ReportPhoto error", e); } }
/// <summary> /// Reports the Annotation as inappropriate. /// </summary> /// <param name="annotation">The annotation to report.</param> public async Task ReportAnnotation(Annotation annotation) { try { var reportContract = new ReportContract { ReportReason = ReportReason.Inappropriate, ContentId = annotation.Id, ContentType = ContentType.Annotation }; await _mobileServiceClient.InvokeApiAsync<ReportContract, ReportContract>("report", reportContract, HttpMethod.Post, null); } catch (Exception e) { throw new ServiceException("ReportAnnotation error", e); } }
/// <summary> /// Inserts a report into Report table. /// </summary> /// <param name="reportContract">The report being inserted.</param> /// <param name="userRegistrationReference">Azure Mobile Service user id who is reporting it.</param> /// <returns>The inserted Report.</returns> public async Task<ReportContract> InsertReport(ReportContract reportContract, string userRegistrationReference) { reportContract.Id = Guid.NewGuid().ToString(); reportContract.ReporterUserId = GetUserDocumentByRegistrationReference(userRegistrationReference).Id; reportContract.CreatedDateTime = DateTime.UtcNow; var reportDocument = ReportDocument.CreateFromContract(reportContract); switch (reportContract.ContentType) { case ContentType.Photo: var photoDocument = GetPhotoDocument(reportContract.ContentId); photoDocument.Report = reportDocument; await ReplacePhotoDocument(photoDocument); break; case ContentType.Annotation: var annotationDocument = GetAnnotationDocument(reportContract.ContentId); annotationDocument.Report = reportDocument; await UpdateAnnotationDocument(annotationDocument); break; default: throw new DataLayerException(DataLayerError.Unknown, "Unknown report content type"); } return reportContract; }
public Task<ReportContract> InsertReport(ReportContract report, string userRegistrationReference) { throw new NotImplementedException(); }