private async Task CreateBlogAsync(UserId newUserId, BlogId newBlogId, TestDatabaseContext testDatabase) { using (var databaseContext = testDatabase.CreateContext()) { await databaseContext.CreateTestBlogAsync(newUserId.Value, newBlogId.Value); } }
public async Task <IActionResult> OnPostSaveComment() { if (HttpContext.User.Identity.Name == null) { return(Redirect("/Account/Login")); } HttpResponseMessage response = new HttpResponseMessage(); var client = _clientFactory.CreateClient(); var blogComment = new BlogWebSite.Models.BlogComments(); blogComment.BlogId = BlogId.GetValueOrDefault(-1); blogComment.Comment = Comment; blogComment.UserId = 1; client.DefaultRequestHeaders.Add("UserName", HttpContext.User.Identity.Name); response = await client.PostAsJsonAsync("https://localhost:44319/api/blogComments/", blogComment); if (response.IsSuccessStatusCode) { return(RedirectToPage("ViewBlog", new { id = BlogId })); } else { return(RedirectToPage("ViewBlog", new { id = BlogId })); } }
public Task <bool> IsWriteAllowedAsync(UserId requester, BlogId blogId) { requester.AssertNotNull("requester"); blogId.AssertNotNull("blogId"); return(this.blogOwnership.IsOwnerAsync(requester, blogId)); }
public ActionResult <BlogId> Create(BlogPost post) { DBBlogPost dbpost = DBToAPIModelTransforms.APItoDBBlogPost(post); DBBlogPost creation = database.createBlogPost(dbpost); BlogId newid = new BlogId(creation.Id, "/blogs/" + creation.Id); return(newid); }
public async Task <BlogSubscriberInformation> GetSubscriberInformation(string blogId) { blogId.AssertUrlParameterProvided("blogId"); var requester = await this.requesterContext.GetRequesterAsync(); var blogIdObject = new BlogId(blogId.DecodeGuid()); return(await this.getBlogSubscriberInformation.HandleAsync(new GetBlogSubscriberInformationQuery(requester, blogIdObject))); }
public async Task <GetFreeAccessUsersResult> GetFreeAccessList(string blogId) { blogId.AssertUrlParameterProvided("blogId"); var requester = await this.requesterContext.GetRequesterAsync(); var blogIdObject = new BlogId(blogId.DecodeGuid()); return(await this.getFreeAccessUsers.HandleAsync(new GetFreeAccessUsersQuery(requester, blogIdObject))); }
public override bool Equals(object obj) { var other = obj as Blog; if (other == null) { return(false); } return(BlogId.Equals(other.BlogId)); }
public async Task AssertWriteAllowedAsync(UserId requester, BlogId blogId) { requester.AssertNotNull("requester"); blogId.AssertNotNull("blogId"); var isUpdateAllowed = await this.IsWriteAllowedAsync(requester, blogId); if (!isUpdateAllowed) { throw new UnauthorizedException("Not allowed to update blog. {0} {1}", requester, blogId); } }
public static CreateBlogCommand NewCreateBlogCommand( UserId userId, BlogId blogId, ChannelId firstChannelId, NewBlogData data) { return(new CreateBlogCommand( Requester.Authenticated(userId), blogId, firstChannelId, ValidBlogName.Parse(data.Name), ValidChannelPrice.Parse(data.BasePrice))); }
public static UpdateBlogCommand NewUpdateBlogCommand( UserId userId, BlogId blogId, UpdatedBlogData data) { return(new UpdateBlogCommand( Requester.Authenticated(userId), blogId, ValidBlogName.Parse(data.Name), ValidIntroduction.Parse(data.Introduction), ValidBlogDescription.Parse(data.Description), data.HeaderImageFileId, ValidExternalVideoUrl.Parse(data.Video))); }
public async Task <bool> ExecuteAsync(BlogId blogId) { using (var connection = this.connectionFactory.CreateConnection()) { var result = await connection.ExecuteScalarAsync <bool>( Sql, new { BlogId = blogId.Value }); return(result); } }
public override IQueryable <Post> GetSatisfiedItems(IQueryable <Post> src) { if (BlogId.GetValueOrDefault() > 0) { src = src.Where(x => x.BlogId == BlogId); } if (PostDateLaterThen > DateTime.MinValue) { src = src.Where(x => x.PostDate > PostDateLaterThen); } return(base.GetSatisfiedItems(src)); }
public async Task ExecuteAsync(UserId userId, BlogId blogId, IReadOnlyList <AcceptedChannelSubscription> channels, DateTime now) { userId.AssertNotNull("userId"); blogId.AssertNotNull("blogId"); if (channels == null || channels.Count == 0) { channels = new List <AcceptedChannelSubscription>(); } using (var transaction = TransactionScopeBuilder.CreateAsync()) { using (var connection = this.connectionFactory.CreateConnection()) { await connection.ExecuteAsync( DeleteStatement, new { BlogId = blogId.Value, SubscriberId = userId.Value, KeepChannelIds = channels.Select(v => v.ChannelId.Value).ToList() }); foreach (var item in channels) { var channelSubscription = new ChannelSubscription( item.ChannelId.Value, null, userId.Value, null, item.AcceptedPrice.Value, now, now); const ChannelSubscription.Fields UpdateFields = ChannelSubscription.Fields.AcceptedPrice | ChannelSubscription.Fields.PriceLastAcceptedDate; await connection.UpsertAsync( channelSubscription, UpdateFields); } } await this.requestSnapshot.ExecuteAsync(userId, SnapshotType.SubscriberChannels); transaction.Complete(); } }
public async Task <GetFreeAccessUsersResult> ExecuteAsync(BlogId blogId) { blogId.AssertNotNull("blogId"); using (var connection = this.connectionFactory.CreateConnection()) { var queryResult = (await connection.QueryAsync <QueryResult>( Query, new { BlogId = blogId.Value })).ToList(); var result = new List <GetFreeAccessUsersResult.FreeAccessUser>(); foreach (var groupedItem in queryResult.GroupBy(v => v.Email)) { var email = groupedItem.Key; var firstItem = groupedItem.First(); if (firstItem.Id.HasValue) { var channelIds = firstItem.ChannelId == null ? EmptyChannelIds : groupedItem.Select(v => new ChannelId(v.ChannelId.Value)).ToList(); var output = new GetFreeAccessUsersResult.FreeAccessUser( new Email(email), new UserId(firstItem.Id.Value), new Username(firstItem.UserName), channelIds); result.Add(output); } else { var output = new GetFreeAccessUsersResult.FreeAccessUser( new Email(email), null, null, EmptyChannelIds); result.Add(output); } } return(new GetFreeAccessUsersResult(result)); } }
private async Task <Blog> CreateBlogAsync(UserId newUserId, BlogId newBlogId, TestDatabaseContext testDatabase) { using (var databaseContext = testDatabase.CreateContext()) { await databaseContext.CreateTestBlogAsync(newUserId.Value, newBlogId.Value, Guid.NewGuid()); var newHeaderImage = FileTests.UniqueEntity(new Random()); newHeaderImage.Id = HeaderImageFileId.Value; newHeaderImage.UserId = newUserId.Value; await databaseContext.Database.Connection.InsertAsync(newHeaderImage); } using (var databaseContext = testDatabase.CreateContext()) { return(await databaseContext.Blogs.SingleAsync(_ => _.Id == newBlogId.Value)); } }
public async Task PutBlogSubscriptions(string blogId, [FromBody] UpdatedBlogSubscriptionData subscriptionData) { blogId.AssertUrlParameterProvided("blogId"); subscriptionData.AssertBodyProvided("subscriptionData"); var subscriptions = subscriptionData.Subscriptions .Select(v => v.Parse()) .Select(v => new AcceptedChannelSubscription(new ChannelId(v.ChannelId.DecodeGuid()), v.AcceptedPrice)).ToList(); var requester = await this.requesterContext.GetRequesterAsync(); var blogIdObject = new BlogId(blogId.DecodeGuid()); await this.updateBlogSubscriptions.HandleAsync(new UpdateBlogSubscriptionsCommand( requester, blogIdObject, subscriptions)); }
public async Task <NewBlogResult> PostBlog(NewBlogData blogData) { blogData.AssertBodyProvided("blogData"); var blog = blogData.Parse(); var requester = await this.requesterContext.GetRequesterAsync(); var newBlogId = new BlogId(this.guidCreator.CreateSqlSequential()); var firstChannelId = new ChannelId(this.guidCreator.CreateSqlSequential()); await this.createBlog.HandleAsync(new CreateBlogCommand( requester, newBlogId, firstChannelId, blog.Name, blog.BasePrice)); return(new NewBlogResult(newBlogId, firstChannelId)); }
public static async Task Seed(PostDbContext dbContext) { // thangchung's user blog var blogId = new BlogId(IdHelper.GenerateId("34c96712-2cdf-4e79-9e2f-768cb68dd552")); var authorId = new AuthorId(IdHelper.GenerateId("4b5f26ce-df97-494c-b747-121d215847d8")); for (var i = 1; i <= 100; i++) { var post = Core.Domain.Post.CreateInstance( blogId, $"The title of post {i}", $"The excerpt of post {i}", $"The body of post {i}", authorId) .AddComment("comment 1", authorId) .AssignTag($"{i}"); dbContext.Add(post); } await dbContext.SaveChangesAsync(); }
public async Task <PutFreeAccessUsersResult> PutFreeAccessList(string blogId, [FromBody] FreeAccessUsersData data) { blogId.AssertUrlParameterProvided("blogId"); data.AssertBodyProvided("blogData"); if (data.Emails == null) { data.Emails = new List <string>(); } var validEmails = new List <ValidEmail>(); var invalidEmails = new HashSet <Email>(); foreach (var email in data.Emails) { if (string.IsNullOrWhiteSpace(email)) { continue; } ValidEmail validEmail; if (ValidEmail.TryParse(email, out validEmail)) { validEmails.Add(validEmail); } else { invalidEmails.Add(new Email(email)); } } var requester = await this.requesterContext.GetRequesterAsync(); var blogIdObject = new BlogId(blogId.DecodeGuid()); await this.updateFreeAccessUsers.HandleAsync(new UpdateFreeAccessUsersCommand( requester, blogIdObject, validEmails)); return(new PutFreeAccessUsersResult(invalidEmails.ToList())); }
public async Task <IHttpActionResult> PutBlog(string blogId, [FromBody] UpdatedBlogData blogData) { blogId.AssertUrlParameterProvided("blogId"); blogData.AssertBodyProvided("blogData"); var blog = blogData.Parse(); var requester = await this.requesterContext.GetRequesterAsync(); var blogIdObject = new BlogId(blogId.DecodeGuid()); await this.updateBlog.HandleAsync(new UpdateBlogCommand( requester, blogIdObject, blog.Name, blog.Introduction, blog.Description, blog.HeaderImageFileId, blog.Video)); return(this.Ok()); }
public static async Task Seed(BlogCoreDbContext dbContext) { var blogId = new BlogId(new Guid("5b1fa7c2-f814-47f2-a2f3-03866f978c49")); for (var i = 1; i <= 1000; i++) { await dbContext.Set <Post>().AddAsync(new Post { Id = Guid.NewGuid(), BlogId = blogId, Title = $"Post {i}", Comments = new List <Comment> { new Comment { Id = Guid.NewGuid() } } }); } await dbContext.SaveChangesAsync(); }
public async Task ExecuteAsync(UserId userId, BlogId blogId, IReadOnlyList <ValidEmail> emails) { userId.AssertNotNull("userId"); blogId.AssertNotNull("blogId"); if (emails == null) { emails = new List <ValidEmail>(); } using (var transaction = TransactionScopeBuilder.CreateAsync()) { using (var connection = this.connectionFactory.CreateConnection()) { if (emails.Count == 0) { await connection.ExecuteAsync( DeleteQuery, new { BlogId = blogId.Value }); } else { await connection.ExecuteAsync( DeleteQuery, new { BlogId = blogId.Value }); await connection.ExecuteAsync( AddQuery, emails.Select(v => new { BlogId = blogId.Value, Email = v.Value }).ToList()); } } await this.requestSnapshot.ExecuteAsync(userId, SnapshotType.CreatorFreeAccessUsers); transaction.Complete(); } }
public override ICollection <LinkCategory> GetActiveCategories() { using (IDataReader reader = _procedures.GetActiveCategoriesWithLinkCollection(BlogId.NullIfMinValue())) { return(reader.ReadLinkCategories(true)); } }
public StartBlog(BlogId id, string name) { Id = id; Name = name; }
public StoryCreatedFromBlog(StoryId id, BlogId blogId, string author, DateTime timeUtc, string title, string body) { Id = id; BlogId = blogId; Author = author; TimeUtc = timeUtc; Title = title; Body = body; }
public SubmitStory(BlogId id, string author, string title, string body) { Id = id; Author = author; Title = title; Body = body; }
public override int GetHashCode() { return(BlogId.GetHashCode()); }
public void ProcessRequest(HttpContext context) { _site = null; if (SiteId != 0) { _site = new AWAPI_BusinessLibrary.library.SiteLibrary().Get(SiteId); } if (_site == null || !_site.isEnabled) { return; } string link = String.IsNullOrEmpty(_site.link) ? "http://awapi.com" : _site.link; _feed = new SyndicationFeed(_site.title + " - Blog Feed", "", new Uri(link)); _feed.Authors.Add(new SyndicationPerson("*****@*****.**")); _feed.AttributeExtensions.Add(new XmlQualifiedName("site"), _site.title); _feed.AttributeExtensions.Add(new XmlQualifiedName("sitelink"), _site.link); _feed.AttributeExtensions.Add(new XmlQualifiedName("defaultculture"), _site.cultureCode); _feed.AttributeExtensions.Add(new XmlQualifiedName("currentpostid"), CurrentPostId.ToString()); _feed.AttributeExtensions.Add(new XmlQualifiedName("servertime"), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")); if (BlogId > 0) { _feed.AttributeExtensions.Add(new XmlQualifiedName("blogid"), BlogId.ToString()); } if (BlogCategoryId > 0) { _feed.AttributeExtensions.Add(new XmlQualifiedName("blogcategoryid"), BlogCategoryId.ToString()); } if (PostId > 0) { _feed.AttributeExtensions.Add(new XmlQualifiedName("postid"), PostId.ToString()); } AddParamsToFeed(); context.Response.ContentType = "text/xml"; context.Response.ContentEncoding = System.Text.Encoding.UTF8; switch (MethodName) { case "getblog": _feed.Title = new TextSyndicationContent(_site.title + " - Blog"); _feed.Categories.Add(new SyndicationCategory("blogs")); GetBlog(SiteId, BlogId); break; case "getbloglist": _feed.Title = new TextSyndicationContent(_site.title + " - Blog List"); _feed.Categories.Add(new SyndicationCategory("blogs")); GetBlogList(SiteId); break; case "getcategorylist": _feed.Title = new TextSyndicationContent(_site.title + " - Blog Category List"); _feed.Categories.Add(new SyndicationCategory("blogs")); GetCategoryList(BlogId); break; case "getpost": _feed.Title = new TextSyndicationContent(_site.title + " - Blog Post"); _feed.Categories.Add(new SyndicationCategory("posts")); GetBlogPost(SiteId, PostId); break; case "getpostfilelist": _feed.Title = new TextSyndicationContent(_site.title + " - Blog Post File List"); _feed.Categories.Add(new SyndicationCategory("files")); GetBlogPostFileList(SiteId, PostId); break; case "getpostlist": _feed.Title = new TextSyndicationContent(_site.title + " - Post List"); _feed.Categories.Add(new SyndicationCategory("posts")); GetBlogPostList(SiteId, BlogId, BlogCategoryId, TagId, Search, PageIndex, PageSize); break; case "getarchivedpostlist": _feed.Title = new TextSyndicationContent(_site.title + " - Archived Post List"); _feed.Categories.Add(new SyndicationCategory("posts")); GetArchivedBlogPostList(SiteId, BlogId, Archive, PageIndex, PageSize); break; case "getarchivelist": _feed.Title = new TextSyndicationContent(_site.title + " - Post Archive List"); _feed.Categories.Add(new SyndicationCategory("posts")); GetBlogPostArchiveList(BlogId); break; case "getcommentlist": _feed.Title = new TextSyndicationContent(_site.title + " - Comment List"); _feed.Categories.Add(new SyndicationCategory("comments")); GetBlogCommentList(SiteId, BlogId, PostId); break; case "gettaglist": _feed.Title = new TextSyndicationContent(_site.title + " - Tag List"); _feed.Categories.Add(new SyndicationCategory("tags")); GetBlogTagList(BlogId, PostId); break; default: break; } WriteFeed(); }
public DecoratedBlog(Blog blog, IDataProtector protector) : base(blog) { ProtectedID = protector.Protect(BlogId.ToString()); }
public BlogStarted(BlogId id, string name, DateTime timeUtc) { Id = id; Name = name; TimeUtc = timeUtc; }
public async Task <GetBlogSubscriberInformationDbStatementResult> ExecuteAsync(BlogId blogId) { blogId.AssertNotNull("blogId"); using (var connection = this.connectionFactory.CreateConnection()) { var result = await connection.QueryAsync <InternalResult>( Sql, new { BlogId = blogId.Value, }); return(new GetBlogSubscriberInformationDbStatementResult( result.Select(v => new GetBlogSubscriberInformationDbStatementResult.Subscriber( new Username(v.Username), new UserId(v.UserId), v.ProfileImageFileId == null ? null : new FileId(v.ProfileImageFileId.Value), new ChannelId(v.ChannelId), DateTime.SpecifyKind(v.SubscriptionStartDate, DateTimeKind.Utc), v.AcceptedPrice, v.Email == null ? null : new Email(v.Email), v.PaymentStatus == null ? PaymentStatus.None : v.PaymentStatus.Value, v.HasPaymentInformation)).ToList())); } }
public override int GetHashCode() => BlogId.GetHashCode();
private async Task CreateEntitiesAsync(TestDatabaseContext testDatabase) { using (var databaseContext = testDatabase.CreateContext()) { // Create header file var blogId = BlogId.Random(); var headerImageFileId = FileId.Random(); await databaseContext.CreateTestBlogAsync(UserId.Value, blogId.Value, headerImageFileId.Value); var headerImageFile = databaseContext.Files.First(v => v.Id == headerImageFileId.Value); headerImageFile.UploadStartedDate = IncludedDate; var channelId = ChannelId.Random(); var channel = ChannelTests.UniqueEntity(Random); channel.BlogId = blogId.Value; channel.Blog = databaseContext.Blogs.First(v => v.Id == blogId.Value); channel.Id = channelId.Value; databaseContext.Channels.Add(channel); // Create profile image file var user = databaseContext.Users.First(v => v.Id == UserId.Value); var profileImageFileId = FileId.Random(); var profileImageFile = this.CreateTestFileWithExistingUserAsync(UserId.Value, profileImageFileId.Value, IncludedDate); databaseContext.Files.Add(profileImageFile); user.ProfileImageFileId = profileImageFileId.Value; // Create image post file. var post1 = PostTests.UniqueFileOrImage(Random); var imageFileId = FileId.Random(); var image = this.CreateTestFileWithExistingUserAsync(UserId.Value, imageFileId.Value, IncludedDate); databaseContext.Files.Add(image); post1.PreviewImageId = imageFileId.Value; post1.PreviewImage = image; post1.ChannelId = channelId.Value; post1.Channel = channel; databaseContext.Posts.Add(post1); var post1File = new PostFile(post1.Id, post1, imageFileId.Value, image); databaseContext.PostFiles.Add(post1File); // Create file post file. var post2 = PostTests.UniqueFileOrImage(Random); var fileFileId = FileId.Random(); var file = this.CreateTestFileWithExistingUserAsync(UserId.Value, fileFileId.Value, IncludedDate); databaseContext.Files.Add(file); post2.ChannelId = channelId.Value; post2.Channel = channel; databaseContext.Posts.Add(post2); var post2File = new PostFile(post2.Id, post2, fileFileId.Value, file); databaseContext.PostFiles.Add(post2File); // Create files excluded because of date. var lateFile1 = this.CreateTestFileWithExistingUserAsync(UserId.Value, FileId.Random().Value, EndDate); databaseContext.Files.Add(lateFile1); var lateFile2 = this.CreateTestFileWithExistingUserAsync(UserId.Value, FileId.Random().Value, Now); databaseContext.Files.Add(lateFile2); // Create orphaned files. var orphanedFile1 = this.CreateTestFileWithExistingUserAsync(UserId.Value, OrphanedFileId1.Value, IncludedDate); databaseContext.Files.Add(orphanedFile1); var orphanedFile2 = this.CreateTestFileWithExistingUserAsync(UserId.Value, OrphanedFileId2.Value, IncludedDate); databaseContext.Files.Add(orphanedFile2); await databaseContext.SaveChangesAsync(); } }
public async Task <GetUserSubscriptionsDbResult> ExecuteAsync(UserId userId) { userId.AssertNotNull("userId"); List <DbResult> subscriptionResults; List <DbResult> freeAccessResults; using (var connection = this.connectionFactory.CreateConnection()) { using (var multi = await connection.QueryMultipleAsync(Sql, new { UserId = userId.Value })) { subscriptionResults = multi.Read <DbResult>().ToList(); freeAccessResults = multi.Read <DbResult>().ToList(); } } var blogs = new Dictionary <BlogId, BlogSubscriptionDbStatus>(); var freeAccessChannelIds = new List <ChannelId>(); foreach (var item in freeAccessResults) { var blogId = new BlogId(item.BlogId); if (!blogs.ContainsKey(blogId)) { var blog = new BlogSubscriptionDbStatus( blogId, item.BlogName, new UserId(item.CreatorId), new Username(item.CreatorUsername), item.ProfileImageFileId.HasValue ? new FileId(item.ProfileImageFileId.Value) : null, true, new List <ChannelSubscriptionStatus>()); blogs.Add(blogId, blog); } freeAccessChannelIds.Add(new ChannelId(item.ChannelId)); } foreach (var item in subscriptionResults) { item.PriceLastSetDate = DateTime.SpecifyKind(item.PriceLastSetDate, DateTimeKind.Utc); item.SubscriptionStartDate = DateTime.SpecifyKind(item.SubscriptionStartDate, DateTimeKind.Utc); var blogId = new BlogId(item.BlogId); BlogSubscriptionDbStatus blog; if (!blogs.TryGetValue(blogId, out blog)) { blog = new BlogSubscriptionDbStatus( blogId, item.BlogName, new UserId(item.CreatorId), new Username(item.CreatorUsername), item.ProfileImageFileId.HasValue ? new FileId(item.ProfileImageFileId.Value) : null, false, new List <ChannelSubscriptionStatus>()); blogs.Add(blogId, blog); } var channel = new ChannelSubscriptionStatus( new ChannelId(item.ChannelId), item.ChannelName, item.AcceptedPrice, item.CurrentPrice, item.PriceLastSetDate, item.SubscriptionStartDate, item.IsVisibleToNonSubscribers); ((List <ChannelSubscriptionStatus>)blog.Channels).Add(channel); } return(new GetUserSubscriptionsDbResult(blogs.Values.ToList(), freeAccessChannelIds)); }
public void When(BlogStarted e) { _id = e.Id; }
public CreateStoryFromBlog(StoryId id, BlogId blogId, string author, string title, string body) { Id = id; BlogId = blogId; Author = author; Title = title; Body = body; }