private string GetParameter(IssueState state, string labels) { var builder = new StringBuilder("?"); builder.Append("state=" + state.ToString().ToLower()); builder.Append(labels != null ? "&labels=" + labels : ""); return(builder.ToString()); }
/// <summary> /// Reports the issue. /// Comment can be null if the <c>IssueState != Other</c> /// </summary> /// <param name="requestId">The request identifier.</param> /// <param name="issue">The issue.</param> /// <param name="comment">The comment.</param> /// <returns></returns> private async Task <Response> ReportIssue(int requestId, IssueState issue, string comment) { if (!Security.HasPermissions(User, Permissions.ReportIssue)) { return(Response.AsJson(new JsonResponseModel { Result = false, Message = "Sorry, you do not have the correct permissions to report an issue." })); } var originalRequest = await Service.GetAsync(requestId); if (originalRequest == null) { return(Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" })); } originalRequest.Issues = issue; originalRequest.OtherMessage = !string.IsNullOrEmpty(comment) ? $"{Username} - {comment}" : string.Empty; var result = await Service.UpdateRequestAsync(originalRequest); var model = new NotificationModel { User = Username, NotificationType = NotificationType.Issue, Title = originalRequest.Title, DateTime = DateTime.Now, Body = issue == IssueState.Other ? comment : issue.ToString().ToCamelCaseWords(), ImgSrc = originalRequest.Type == RequestType.Movie ? $"https://image.tmdb.org/t/p/w300/{originalRequest.PosterPath}" : originalRequest.PosterPath }; await NotificationService.Publish(model); return(Response.AsJson(result ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" })); }
/// <summary> /// Reports the issue. /// Comment can be null if the <c>IssueState != Other</c> /// </summary> /// <param name="requestId">The request identifier.</param> /// <param name="issue">The issue.</param> /// <param name="comment">The comment.</param> /// <returns></returns> private Response ReportIssue(int requestId, IssueState issue, string comment) { var originalRequest = Service.Get(requestId); if (originalRequest == null) { return(Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" })); } originalRequest.Issues = issue; originalRequest.OtherMessage = !string.IsNullOrEmpty(comment) ? $"{Username} - {comment}" : string.Empty; var result = Service.UpdateRequest(originalRequest); var model = new NotificationModel { User = Username, NotificationType = NotificationType.Issue, Title = originalRequest.Title, DateTime = DateTime.Now, Body = issue == IssueState.Other ? comment : issue.ToString().CamelCaseToWords() }; NotificationService.Publish(model); return(Response.AsJson(result ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = "Could not add issue, please try again or contact the administrator!" })); }
private async Task <Response> ReportNonRequestIssue(int providerId, string type, IssueState issue, string comment) { var currentIssues = await IssuesService.GetAllAsync(); var notifyModel = new NotificationModel { User = Username, NotificationType = NotificationType.Issue, DateTime = DateTime.Now, Body = issue == IssueState.Other ? comment : issue.ToString().ToCamelCaseWords() }; var model = new IssueModel { Issue = issue, UserReported = Username, UserNote = !string.IsNullOrEmpty(comment) ? $"{Username} - {comment}" : string.Empty, }; var existing = currentIssues.FirstOrDefault(x => x.ProviderId == providerId && !x.Deleted && x.IssueStatus == IssueStatus.PendingIssue); if (existing != null) { existing.Issues.Add(model); await IssuesService.UpdateIssueAsync(existing); return(Response.AsJson(new JsonResponseModel { Result = true })); } if (type == "movie") { var movieApi = new TheMovieDbApi(); var result = await movieApi.GetMovieInformation(providerId); if (result != null) { notifyModel.Title = result.Title; // New issue var issues = new IssuesModel { Title = result.Title, PosterUrl = "https://image.tmdb.org/t/p/w150/" + result.PosterPath, ProviderId = providerId, Type = RequestType.Movie, IssueStatus = IssueStatus.PendingIssue }; issues.Issues.Add(model); var issueId = await IssuesService.AddIssueAsync(issues); await NotificationService.Publish(notifyModel); return(Response.AsJson(new JsonResponseModel { Result = true })); } } if (type == "tv") { var tv = new TvMazeApi(); var result = tv.ShowLookupByTheTvDbId(providerId); if (result != null) { var banner = result.image?.medium; if (!string.IsNullOrEmpty(banner)) { banner = banner.Replace("http", "https"); } notifyModel.Title = result.name; // New issue var issues = new IssuesModel { Title = result.name, PosterUrl = banner, ProviderId = providerId, Type = RequestType.TvShow, IssueStatus = IssueStatus.PendingIssue }; issues.Issues.Add(model); var issueId = await IssuesService.AddIssueAsync(issues); await NotificationService.Publish(notifyModel); return(Response.AsJson(new JsonResponseModel { Result = true })); } } return(Response.AsJson(new JsonResponseModel { Result = false, Message = "Album Reports are not supported yet!" })); }
private async Task <Response> ReportRequestIssue(int requestId, IssueState issue, string comment) { var model = new IssueModel { Issue = issue, UserReported = Username, UserNote = !string.IsNullOrEmpty(comment) ? $"{Username} - {comment}" : string.Empty, }; var request = await RequestService.GetAsync(requestId); var issueEntity = await IssuesService.GetAllAsync(); var existingIssue = issueEntity.FirstOrDefault(x => x.RequestId == requestId); var notifyModel = new NotificationModel { User = Username, NotificationType = NotificationType.Issue, Title = request.Title, DateTime = DateTime.Now, Body = issue == IssueState.Other ? comment : issue.ToString().ToCamelCaseWords() }; // An issue already exists if (existingIssue != null) { if (existingIssue.Issues.Any(x => x.Issue == issue)) { return (Response.AsJson(new JsonResponseModel { Result = false, Message = "This issue has already been reported!" })); } existingIssue.Issues.Add(model); var result = await IssuesService.UpdateIssueAsync(existingIssue); await NotificationService.Publish(notifyModel); return(Response.AsJson(result ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false })); } // New issue var issues = new IssuesModel { Title = request.Title, PosterUrl = request.PosterPath, RequestId = requestId, Type = request.Type, IssueStatus = IssueStatus.PendingIssue }; issues.Issues.Add(model); var issueId = await IssuesService.AddIssueAsync(issues); request.IssueId = issueId; await RequestService.UpdateRequestAsync(request); await NotificationService.Publish(notifyModel); return(Response.AsJson(new JsonResponseModel { Result = true })); }