Example #1
0
        public async Task <ActionResult <Book> > RollBackAsync(string id, RollbackRequest request, [FromQuery] string reason = null)
        {
            var result = await _snapshots.GetAsync(ObjectType.Book, request.SnapshotId);

            if (!result.TryPickT0(out var snapshot, out _))
            {
                return(ResultUtilities.NotFound(request.SnapshotId));
            }

            var rollbackResult = await _snapshots.RollbackAsync <DbBook>(snapshot, new SnapshotArgs
            {
                Committer = User,
                Event     = SnapshotEvent.AfterRollback,
                Reason    = reason,
                Rollback  = snapshot,
                Source    = SnapshotSource.User
            });

            if (!rollbackResult.TryPickT0(out var value, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            var(book, _) = value;

            return(book.Convert(_services));
        }
        public async Task <ActionResult> StripeCallbackAsync()
        {
            Event stripeEvent;

            try
            {
                stripeEvent = EventUtility.ConstructEvent(
                    await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(),
                    Request.Headers["Stripe-Signature"],
                    _stripeOptions.CurrentValue.WebhookSecret,
                    throwOnApiVersionMismatch: false);
            }
            catch (StripeException)
            {
                // event construction failed, so request wasn't valid
                return(ResultUtilities.BadRequest("You're not stripe, are you?"));
            }

            switch (stripeEvent.Type)
            {
            case Events.CheckoutSessionCompleted when stripeEvent.Data.Object is Session session:
                await _stripe.HandleSupporterCheckoutCompletedAsync(session);

                break;

            default:
                return(ResultUtilities.BadRequest($"Stripe event {stripeEvent.Type} should not be received by this server."));
            }

            return(Ok());
        }
Example #3
0
        public async Task <ActionResult <BookContent> > UpdateContentAsync(string id, string contentId, BookContentBase model)
        {
            using (await _locker.EnterAsync(id))
            {
                var book = await _books.GetAsync(id);

                if (book == null)
                {
                    return(ResultUtilities.NotFound <Book>(id));
                }

                var content = book.Contents.FirstOrDefault(c => c.Id == contentId);

                if (content == null)
                {
                    return(ResultUtilities.NotFound <BookContent>(id, contentId));
                }

                _mapper.Map(model, content);

                await _books.UpdateAsync(book);

                await _snapshots.ModifiedAsync(book);

                return(content);
            }
        }
Example #4
0
        public string Editor()
        {
            SetSite();
            switch (ReferenceType)
            {
            case "Sites": return(SiteUtilities.Editor(ReferenceId, clearSessions: true));

            case "Issues": return(IssueUtilities.Editor(
                                      ss: Site.IssuesSiteSettings(ReferenceId),
                                      issueId: ReferenceId,
                                      clearSessions: true));

            case "Results": return(ResultUtilities.Editor(
                                       ss: Site.ResultsSiteSettings(ReferenceId),
                                       resultId: ReferenceId,
                                       clearSessions: true));

            case "Wikis": return(WikiUtilities.Editor(
                                     ss: Site.WikisSiteSettings(ReferenceId),
                                     wikiId: ReferenceId,
                                     clearSessions: true));

            default: return(HtmlTemplates.Error(Error.Types.NotFound));
            }
        }
Example #5
0
        public async Task <JsonResult> Logout()
        {
            await signInManager.SignOutAsync();

            logger.LogDebug("用户登出");
            return(Json(ResultUtilities.Success()));
        }
Example #6
0
        public System.Web.Mvc.ContentResult GetByApi()
        {
            SetSite();
            switch (Site.ReferenceType)
            {
            case "Issues":
                if (SiteId == ReferenceId)
                {
                    return(IssueUtilities.GetByApi(
                               ss: Site.IssuesSiteSettings(ReferenceId)));
                }
                else
                {
                    return(IssueUtilities.GetByApi(
                               ss: Site.IssuesSiteSettings(ReferenceId),
                               issueId: ReferenceId));
                }

            case "Results":
                if (SiteId == ReferenceId)
                {
                    return(ResultUtilities.GetByApi(
                               ss: Site.ResultsSiteSettings(ReferenceId)));
                }
                else
                {
                    return(ResultUtilities.GetByApi(
                               ss: Site.ResultsSiteSettings(ReferenceId),
                               resultId: ReferenceId));
                }

            default: return(ApiResults.Get(ApiResponses.BadRequest()));
            }
        }
Example #7
0
        public async Task <ActionResult <Book> > GetAsync(string id)
        {
            var result = await _books.GetAsync(id);

            if (!result.TryPickT0(out var book, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            return(book.Convert(_services));
        }
Example #8
0
        public ActionResult <UploadState> GetUpload(string id)
        {
            var task = _uploads.GetTask <BookUpload>(id);

            if (task == null)
            {
                return(ResultUtilities.NotFound <UploadTask>(id));
            }

            return(task);
        }
Example #9
0
        public async Task <ActionResult <Collection> > GetAsync(string id)
        {
            var result = await _collections.GetAsync(id);

            if (!result.TryPickT0(out var collection, out _) || !CurrentConstraint.Test(collection))
            {
                return(ResultUtilities.NotFound(id));
            }

            return(collection.Convert(_services));
        }
Example #10
0
        public async Task <ActionResult <Collection> > UpdateAsync(string id, CollectionBase model)
        {
            var result = await _collections.UpdateAsync(id, model, CurrentConstraint);

            if (!result.TryPickT0(out var collection, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            return(collection.Convert(_services));
        }
Example #11
0
        public async Task <ActionResult <Vote> > GetVoteAsync(string id)
        {
            var result = await _votes.GetAsync(UserId, new nhitomiObject(ObjectType.Book, id));

            if (!result.TryPickT0(out var vote, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            return(vote.Convert(_services));
        }
Example #12
0
        public async Task <ActionResult <Collection> > SortItemsAsync(string id, CollectionItemsRequest request)
        {
            var result = await _collections.SortAsync(id, request.Items, CurrentConstraint);

            if (!result.TryPickT0(out var collection, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            return(collection.Convert(_services));
        }
Example #13
0
        public async Task <ActionResult <Book> > RefreshContentAsync(string id, RefreshContentRequest request)
        {
            var result = await _books.RefreshAsync(id, request.ContentId);

            if (!result.TryPickT0(out var value, out _))
            {
                return(ResultUtilities.NotFound(id, request.ContentId));
            }

            return(value.Convert(_services));
        }
Example #14
0
        public async Task <ActionResult <Book> > GetAsync(string id)
        {
            var book = await _books.GetAsync(id);

            if (book == null)
            {
                return(ResultUtilities.NotFound <Book>(id));
            }

            return(book);
        }
Example #15
0
        public async Task <ActionResult <Snapshot> > GetSnapshotAsync(string id)
        {
            var result = await _snapshots.GetAsync(ObjectType.Book, id);

            if (!result.TryPickT0(out var snapshot, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            return(snapshot.Convert(_services));
        }
Example #16
0
        public async Task <ActionResult <User> > GetAsync(string id)
        {
            var result = await _users.GetAsync(id);

            if (!result.TryPickT0(out var user, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            return(ProcessUser(user.Convert(_services)));
        }
Example #17
0
        public async Task <ActionResult <DownloadSession> > GetSessionAsync(string id)
        {
            var result = await _downloads.GetSessionAsync(id);

            if (!result.TryPickT0(out var session, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            return(session.Convert());
        }
Example #18
0
        public async Task <ActionResult <SearchResult <Collection> > > GetCollectionsAsync(string id)
        {
            if (UserId != id && !User.HasPermissions(UserPermissions.ManageUsers))
            {
                return(ResultUtilities.Forbidden("Insufficient permissions to see user collections."));
            }

            var result = await _collections.GetUserCollectionsAsync(id);

            return(result.Project(c => c.Convert(_services)));
        }
Example #19
0
        public string BulkDelete()
        {
            SetSite();
            switch (Site.ReferenceType)
            {
            case "Issues": return(IssueUtilities.BulkDelete(Site.IssuesSiteSettings(ReferenceId)));

            case "Results": return(ResultUtilities.BulkDelete(Site.ResultsSiteSettings(ReferenceId)));

            default: return(Messages.ResponseNotFound().ToJson());
            }
        }
Example #20
0
        public string Import()
        {
            SetSite();
            switch (Site.ReferenceType)
            {
            case "Issues": return(IssueUtilities.Import(siteModel: Site));

            case "Results": return(ResultUtilities.Import(siteModel: Site));

            default: return(Messages.ResponseNotFound().ToJson());
            }
        }
Example #21
0
        public static string DisplayValue(SiteSettings ss, DataRow dataRow)
        {
            switch (ss.ReferenceType)
            {
            case "Issues": return(IssueUtilities.TitleDisplayValue(ss, dataRow));

            case "Results": return(ResultUtilities.TitleDisplayValue(ss, dataRow));

            case "Wikis": return(WikiUtilities.TitleDisplayValue(ss, dataRow));

            default: return(string.Empty);
            }
        }
Example #22
0
        public string IndexJson()
        {
            SetSite(initSiteSettings: true);
            ViewModes.Set(Site.SiteId);
            switch (Site.ReferenceType)
            {
            case "Issues": return(IssueUtilities.IndexJson(ss: Site.SiteSettings));

            case "Results": return(ResultUtilities.IndexJson(ss: Site.SiteSettings));

            default: return(HtmlTemplates.Error(Error.Types.NotFound));
            }
        }
Example #23
0
        public async Task <ActionResult <DownloadSession> > CreateSessionAsync(CreateSessionRequest request)
        {
            var __ = request;

            var result = await _downloads.CreateSessionAsync(UserId);

            if (!result.TryPickT0(out var session, out _))
            {
                return(ResultUtilities.BadRequest("Maximum number of download sessions has been reached."));
            }

            return(session.Convert());
        }
Example #24
0
        public async Task <ActionResult <Vote> > SetVoteAsync(string id, VoteBase model)
        {
            var result = await _books.GetAsync(id);

            if (!result.TryPickT0(out var book, out _))
            {
                return(ResultUtilities.NotFound(id));
            }

            var vote = await _votes.SetAsync(UserId, book, model.Type);

            return(vote.Convert(_services));
        }
Example #25
0
        public async Task <ActionResult <BookContent> > GetContentAsync(string id, string contentId)
        {
            var result = await _books.GetContentAsync(id, contentId);

            if (!result.TryPickT0(out var value, out _))
            {
                return(ResultUtilities.NotFound(id, contentId));
            }

            var(_, content) = value;

            return(content.Convert(_services));
        }
Example #26
0
        public string New()
        {
            SetSite(siteOnly: true, initSiteSettings: true);
            switch (Site.ReferenceType)
            {
            case "Issues": return(IssueUtilities.EditorNew(Site.SiteSettings));

            case "Results": return(ResultUtilities.EditorNew(Site.SiteSettings));

            case "Wikis": return(WikiUtilities.EditorNew(Site.SiteSettings));

            default: return(HtmlTemplates.Error(Error.Types.NotFound));
            }
        }
Example #27
0
        public ResponseFile Export()
        {
            SetSite();
            switch (Site.ReferenceType)
            {
            case "Issues": return(IssueUtilities.Export(
                                      Site.IssuesSiteSettings(ReferenceId), siteModel: Site));

            case "Results": return(ResultUtilities.Export(
                                       Site.ResultsSiteSettings(ReferenceId), siteModel: Site));

            default: return(null);
            }
        }
        public static string LinkSourceResponse(long siteId, long id)
        {
            var siteModel = new SiteModel(siteId);
            var ss        = SiteSettingsUtilities.Get(siteModel, id);

            switch (ss.ReferenceType)
            {
            case "Issues": return(IssueUtilities.EditorJson(ss, id));

            case "Results": return(ResultUtilities.EditorJson(ss, id));

            default: return(null);
            }
        }
Example #29
0
        public System.Web.Mvc.ContentResult CreateByApi()
        {
            SetSite();
            switch (Site.ReferenceType)
            {
            case "Issues": return(IssueUtilities.CreateByApi(
                                      ss: Site.IssuesSiteSettings(ReferenceId)));

            case "Results": return(ResultUtilities.CreateByApi(
                                       ss: Site.ResultsSiteSettings(ReferenceId)));

            default: return(ApiResults.Get(ApiResponses.BadRequest()));
            }
        }
Example #30
0
        public string UpdateByKamban()
        {
            SetSite();
            switch (Site.ReferenceType)
            {
            case "Issues": return(IssueUtilities.UpdateByKamban(
                                      Site.IssuesSiteSettings(ReferenceId, setAllChoices: true)));

            case "Results": return(ResultUtilities.UpdateByKamban(
                                       Site.ResultsSiteSettings(ReferenceId, setAllChoices: true)));

            default: return(Messages.ResponseNotFound().ToJson());
            }
        }