Esempio n. 1
0
        /// <summary>
        /// The add post.
        /// </summary>
        /// <param name="postEntity">
        /// The post entity.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int AddPost(PostEntity postEntity)
        {
            int postID = -1;

            try
            {
                postID = this.AddPostInternal(postEntity);

                this.categoryService.AddCategoryMapping(postEntity.Categories, postID);

                if (postEntity.Tags != null)
                {
                    this.tagService.AddTagsForPost(postEntity.Tags, postID);
                }

                return(postID);
            }
            catch
            {
                if (postID > 0)
                {
                    this.categoryService.DeleteCategoryMapping(postID);
                    this.tagService.DeleteTagsForPost(postID);
                }

                this.DeletePost(postID);

                return(-1);
            }
        }
Esempio n. 2
0
        public bool Remove(string commentId)
        {
            try
            {
                DbSet <CommentEntity> commentEntityDbSet = Context.CommentEntities;

                IQueryable <CommentEntity> childCommentQueryable = commentEntityDbSet
                                                                   .Where(x => x.ParentComment.CommentId.Equals(commentId));

                List <CommentEntity> childCommentEntities = childCommentQueryable.ToList();

                CommentEntity commentEntity = commentEntityDbSet
                                              .Include(x => x.Post)
                                              .Where(x => x.CommentId.Equals(commentId))
                                              .First();

                PostEntity postEntity = commentEntity.Post;

                postEntity.CommentCount -= (childCommentEntities.Count + 1);
                commentEntityDbSet.RemoveRange(childCommentEntities);
                commentEntityDbSet.Remove(commentEntity);

                Context.SaveChanges();
                Context.Entry(postEntity).State = EntityState.Detached;

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (PostEntity pe = new PostEntity())
                {
                    var user = pe.Subscriber_Table.Where(x => x.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.password          = Crypto.Hash(model.NewPassword);
                        user.ResetPasswordCode = "";
                        pe.Configuration.ValidateOnSaveEnabled = false;
                        pe.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something invalid";
            }

            ViewBag.Message = message;
            return(View(model));
        }
Esempio n. 4
0
        /// <summary>
        /// The add post internal.
        /// </summary>
        /// <param name="postEntity">
        /// The post entity.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int AddPostInternal(PostEntity postEntity)
        {
            this.postTable.InsertOnSubmit(postEntity);
            this.Context.SubmitChanges();

            return(postEntity.ID);
        }
 public ActionResult DeletePost(int id)
 {
     using (PostEntity pe = new PostEntity())
     {
         return(View(pe.Post_Table.Where(x => x.postid == id).FirstOrDefault()));
     }
 }
        public ActionResult ForgotPassword(string EmailID)
        {
            //Verify the emailid
            //Generate Reset Password Link
            //Send Email
            string message = "";
            bool   status  = false;

            using (PostEntity pe = new PostEntity())
            {
                var account = pe.Subscriber_Table.Where(x => x.email == EmailID).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;

                    pe.Configuration.ValidateOnSaveEnabled = false;
                    pe.SaveChanges();
                    message = "Reset Password Link has been sent to your Email ID";
                }
                else
                {
                    message = "Account Not Found";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
Esempio n. 7
0
        /// <summary>
        /// Get tags container for team post.
        /// </summary>
        /// <param name="teamPost">Team post entity object.</param>
        /// <returns>Return a container for team post tags.</returns>
        private AdaptiveContainer GetTagsContainer(PostEntity teamPost)
        {
            var tagsContainer = new AdaptiveContainer
            {
                Items = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Stretch,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = $"**{this.localizer.GetString("TagsLabelText")}{":"}** {teamPost.Tags?.Replace(";", ", ", false, CultureInfo.InvariantCulture)}",
                                        Wrap = true,
                                    },
                                },
                            },
                        },
                    },
                },
            };

            return(tagsContainer);
        }
        public ActionResult ManageUser()
        {
            using (PostEntity pe = new PostEntity())
            {
                string            userid  = Session["userid"].ToString();
                List <Post_Table> article = pe.Post_Table.Where(x => x.userid.Equals(userid) && x.category == true).ToList();
                List <Post_Table> blog    = pe.Post_Table.Where(x => x.userid.Equals(userid) && x.category == false).ToList();

                if (article.Count > 0)
                {
                    ViewData["Articles"] = article;
                }
                else
                {
                    ViewData["Articles"]   = null;
                    ViewBag.ArticleMessage = "No articles published ";
                }

                if (blog.Count > 0)
                {
                    ViewData["Blogs"] = blog;
                }
                else
                {
                    ViewData["Blogs"]   = null;
                    ViewBag.BlogMessage = "No blogs posted ";
                }



                return(View());
            }
        }
Esempio n. 9
0
        private async Task <bool> GetApiToDatabase()
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                var posts = await postApi.Get("albumId", albumModel.Id.ToString());

                foreach (var post in posts)
                {
                    var postDb = postDatabase.Get(i => i.Id == post.Id);
                    if (postDb.Any())
                    {
                        continue;
                    }

                    var postToInsert = new PostEntity()
                    {
                        Id      = post.Id,
                        Title   = post.Title,
                        Body    = post.Body,
                        AlbumId = post.AlbumId
                    };

                    postDatabase.Insert(postToInsert);
                }

                return(await Task.FromResult(true));
            }

            return(await Task.FromResult(false));
        }
Esempio n. 10
0
        public async Task <bool> CreatePostAsync(PostEntity entity)
        {
            entity.PostDate = DateTime.UtcNow;
            await _dbContext.Posts.AddAsync(entity);

            return(await SaveAsync());
        }
Esempio n. 11
0
 public PostEntity Add(PostEntity post)
 {
     post.dt_created = DateTime.Now;
     _posts.Add(post);
     _posts.SaveChanges();
     return(post);
 }
Esempio n. 12
0
        public override bool Add(CommentEntity commentEntity)
        {
            try
            {
                //Get and track post.
                //Update number of comments in post.
                PostEntity postEntity = Context.PostEntities
                                        .Where(x => x.PostId.Equals(commentEntity.PostId))
                                        .First();

                postEntity.CommentCount++;

                //Attach to track new comment.
                //Add comment.
                Context.CommentEntities.Attach(commentEntity);
                DbEntityEntry <CommentEntity> commentEntry = Context.Entry(commentEntity);
                commentEntry.State = EntityState.Added;

                Context.SaveChanges();

                //Detach post and comment to stop tracking.
                Context.Entry(postEntity).State = EntityState.Detached;
                commentEntry.State = EntityState.Detached;

                return(true);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                return(false);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 向数据源中添加帖子。
        /// </summary>
        /// <param name="dataFacade">数据源的外观。</param>
        /// <param name="indexEntity">帖子索引实体对象。</param>
        /// <param name="contentEntity">帖子内容对象。</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="dataFacade"/>为null
        ///     或
        ///     <paramref name="indexEntity"/>为null
        ///     或
        ///     <paramref name="contentEntity"/>为null
        /// </exception>
        /// <exception cref="DataFacadeException">数据源抛出了未经处理的异常</exception>
        public static async Task <int> AddPost(this IDataFacade dataFacade,
                                               PostEntity indexEntity, PostContentEntity contentEntity)
        {
            if (dataFacade == null)
            {
                throw new ArgumentNullException(nameof(dataFacade));
            }
            if (indexEntity == null)
            {
                throw new ArgumentNullException(nameof(indexEntity));
            }
            if (contentEntity == null)
            {
                throw new ArgumentNullException(nameof(contentEntity));
            }

            // 将内容实体对象插入到数据源中。
            await dataFacade.AddPostContentEntity(contentEntity);

            // 将帖子索引实体对象插入到数据源中。
            dataFacade.AddPostIndexEntity(indexEntity);
            await dataFacade.CommitChanges();

            return(indexEntity.Id);
        }
Esempio n. 14
0
        public Post Put(int id, [FromBody] PostEntity obj)
        {
            Post post = PostBuilder.Build(obj);

            post = this.PostRepository.Update(post, id);
            return(post ?? null);
        }
Esempio n. 15
0
        public PostEntity ModelToEntity(PostModel postModel)
        {
            if (postModel == null)
            {
                return(null);
            }

            var postEntity = new PostEntity
            {
                Author     = postModel.Author,
                AuthorName = postModel.AuthorName,
                Date       = postModel.Date,
                Id         = postModel.Id,
                Team       = postModel.Team,
                Text       = postModel.Text,
                Title      = postModel.Title,
                Comments   = new Collection <CommentEntity>()
            };

            if (postModel.Comments == null)
            {
                postModel.Comments = new Collection <CommentModel>();
            }
            else
            {
                var commentMapper = new CommentMapper();
                foreach (var comment in postModel.Comments)
                {
                    postEntity.Comments.Add(commentMapper.ModelToEntity(comment));
                }
            }
            return(postEntity);
        }
Esempio n. 16
0
 public void DeletePost(PostEntity oldPost)
 {
     NullRefCheck();
     ArgumentNullCheck(oldPost);
     postRepository.Delete(oldPost.ToDalPost());
     uow.Commit();
 }
Esempio n. 17
0
        public async Task <IActionResult> Edit(int id, PostEntity postEntity)
        {
            if (id != postEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _postService.UpdateAsync(postEntity);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (await _postService.GetByIdAsync(id) == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(postEntity));
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            System.Net.WebClient client = new System.Net.WebClient();
            var result = client.DownloadString("http://www.asp.net//");


            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.OptionAutoCloseOnEnd  = true;
            htmlDoc.OptionFixNestedTags   = true;
            htmlDoc.OptionWriteEmptyNodes = true;
            htmlDoc.LoadHtml(result);

            var selectedItems = from articulos in htmlDoc.DocumentNode
                                .QuerySelectorAll("div.col-center div.common-post")
                                select new
            {
                p = articulos.QuerySelector("p.excerpt").InnerText
            };

            CloudTable table = inicializarStorage("Postaspnet");

            foreach (var item in selectedItems)
            {
                PostEntity     post            = new PostEntity(item.p);
                TableOperation insertOperation = TableOperation.Insert(post);
                table.Execute(insertOperation);
            }


            Console.Write("Guardo");
        }
Esempio n. 19
0
        public PostEntity Add(PostEntity postEntity)
        {
            try
            {
                if (postEntity != null)
                {
                    var post = new Post();
                    post.Name        = postEntity.Name;
                    post.Alias       = postEntity.Alias;
                    post.Content     = postEntity.Content;
                    post.Description = postEntity.Description;
                    post.ExpireDate  = postEntity.ExpireDate;
                    post.HomeFlag    = postEntity.HomeFlag;
                    post.HotFlag     = postEntity.HotFlag;
                    post.Image       = postEntity.Image;
                    post.MoreImages  = postEntity.MoreImages;
                    post.PostTypeID  = postEntity.PostTypeID;
                    post.Status      = postEntity.Status;
                    post.Tags        = postEntity.Tags;
                    _postRepository.Add(post);
                }
                _unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                string FunctionName = string.Format("AddRoom('{0}')", postEntity);
                Common.Logs.LogCommon.WriteError(ex.ToString(), FunctionName);
                return(null);
            }

            return(postEntity);
        }
Esempio n. 20
0
 public PostModel(PostEntity post)
 {
     Id        = post.Id;
     Title     = post.Title;
     Content   = post.Content;
     TimeStamp = post.TimeStamp;
 }
Esempio n. 21
0
 public void Update(PostEntity post)
 {
     NullRefCheck();
     ArgumentNullCheck(post);
     postRepository.Update(post.ToDalPost());
     uow.Commit();
 }
        // TODO: Add authors projection in its real form, not just out of createdby
        // TODO: Add CommentStatusActionRecord projection
        // TODO: Add ApprovalStatusActionRecord projection
        public static PostReadModel ToReadModel(this PostEntity postEntity, IEnumerable <Claim> authorClaims)
        {
            var createdBy = postEntity.CreatedBy.ToDomainModel(authorClaims);
            var slugs     = postEntity.Slugs.Select(x => x.ToReadModel()).ToList().AsReadOnly();
            var tags      = postEntity.Tags
                            .Where(x => x.Tag != null) // it comes up null sometimes, no clue why as it's 'ThenInclude'd
                            .Select(x => x.ToReadModel()).ToList().AsReadOnly();

            return(new PostReadModel
            {
                Id = postEntity.Id.ToString(),
                Language = postEntity.Language,
                Title = postEntity.Title,
                Abstract = postEntity.Abstract,
                Content = postEntity.Content,
                Slugs = slugs,
                Tags = tags,
                Authors = new List <UserReadModel> {
                    createdBy
                }.AsReadOnly(),
                ApprovalStatus = postEntity.ApprovalStatus.ToDomainModel(),
                CreationRecord = new ChangeRecordReadModel
                {
                    RecordedBy = createdBy,
                    RecordedOn = postEntity.CreatedOnUtc,
                    IpAddress = postEntity.CreationIpAddress
                }
            });
        }
Esempio n. 23
0
        public async Task <IActionResult> PutPostEntity(Guid id, PostEntity postEntity)
        {
            if (id != postEntity.Id)
            {
                return(BadRequest());
            }

            _context.Entry(postEntity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostEntityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 24
0
        public PostDTO GetPost(string id)
        {
            PostEntity postEntity = postRepository.GetPost(id);
            PostDTO    postDTO    = dataMapper.MapPostEntityToDTO(postEntity);

            return(postDTO);
        }
Esempio n. 25
0
        public ActionResult DeleteConfirmed(int id = 0)
        {
            PostEntity post = postService.GetPostEntity(id);

            postService.DeletePost(post);
            return(RedirectToAction("Cabinet", "User"));
        }
Esempio n. 26
0
        public async Task <IActionResult> AssociatePost(Guid groupId, Guid postId)
        {
            using SqlConnection connection = this.userService.Connection;
            UserEntity user = await this.userDatabaseAccess.Get(this.userService.Username, connection);

            DateTime now = DateTime.Now;

            using DatabaseContext context = new DatabaseContext(connection);
            PostEntity postEntity = await context.Post.FindAsync(postId);

            if (postEntity.AuthorId != user.Id)
            {
                throw new Exception("This post was made by another user");
            }

            PostGroupEntity postGroup = new PostGroupEntity()
            {
                CreationDate = now,
                GroupId      = groupId,
                PostId       = postId
            };

            await context.PostGroup.AddAsync(postGroup);

            await context.SaveChangesAsync();

            return(this.Ok());
        }
        public IActionResult AddOrUpdate([FromBody] PostModel model)
        {
            PostEntity entity = null;

            entity = this.dbContext.Posts.FirstOrDefault(x => x.Id == model.Id);
            if (entity == null)
            {
                entity = new PostEntity {
                    CreateDate = DateTime.Now
                };
                this.dbContext.Posts.Add(entity);
            }
            entity.Title = model.Title;
            entity.Text  = model.Text;
            this.dbContext.SaveChanges();

            var postModel = new PostModel
            {
                Id         = entity.Id,
                CreateDate = entity.CreateDate,
                Title      = entity.Title,
                Text       = entity.Text
            };

            return(Json(postModel));
        }
Esempio n. 28
0
        public async Task <IActionResult> Edit(Guid id, [Bind("ID,Title,ShortDescription,MainContent,Slug,CreatedDate,UpdatedDate,ThumbnailImage,AuthorID")] PostEntity postEntity)
        {
            if (id != postEntity.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(postEntity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostEntityExists(postEntity.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorID"] = new SelectList(_context.Accounts, "ID", "FirstName", postEntity.AuthorID);
            return(View(postEntity));
        }
Esempio n. 29
0
        public PostModel EntityToModel(PostEntity postEntity)
        {
            if (postEntity == null)
            {
                return(null);
            }

            var postModel = new PostModel
            {
                Id         = postEntity.Id,
                Author     = postEntity.Author,
                AuthorName = postEntity.AuthorName,
                Text       = postEntity.Text,
                Date       = postEntity.Date,
                Title      = postEntity.Title,
                Team       = postEntity.Team,
                Comments   = new Collection <CommentModel>()
            };

            if (postEntity.Comments == null)
            {
                postEntity.Comments = new Collection <CommentEntity>();
            }
            else
            {
                var commentMapper = new CommentMapper();
                foreach (var comment in postEntity.Comments)
                {
                    postModel.Comments.Add(commentMapper.EntityToModel(comment));
                }
            }
            return(postModel);
        }
Esempio n. 30
0
        public async Task <ActionResult <PostEntity> > PostPostEntity(PostEntity postEntity)
        {
            _context.Posts.Add(postEntity);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPostEntity", new { id = postEntity.Id }, postEntity));
        }
Esempio n. 31
0
        public override void Under_These_Conditions()
        {
            repository = IoC.Resolve<IPostRepository>();

            blog = new BlogEntity {Host = "localhost"};

            Repository<BlogEntity>.SaveOrUpdate(blog);

            UnitOfWork.Current.Flush();

            post = new PostEntity
                       {
                           Blog = blog,
                           DatePublished = DateTime.Today,
                           Title = "Test",
                           Text = "This is a test",
                           Slug = "This-is-a-clean-url"
                       };
        }
Esempio n. 32
0
 public void Can_Get_Set_DatePublished()
 {
     var post = new PostEntity();
     post.DatePublished = DateTime.Today;
     post.DatePublished.ShouldBe(DateTime.Today);
 }
Esempio n. 33
0
 public void Can_Create_Post()
 {
     var post = new PostEntity();
     post.ShouldNotBeNull();
 }
Esempio n. 34
0
 public void Can_Get_Date()
 {
     var post = new PostEntity();
     post.DateCreated.ShouldNotBeNull();
 }
Esempio n. 35
0
 public void Can_Get_Set_Blog()
 {
     var post = new PostEntity();
     post.Blog = new BlogEntity();
     post.Blog.ShouldNotBeNull();
 }
Esempio n. 36
0
 public void Can_Get_Set_Text()
 {
     var post = new PostEntity();
     post.Text = "This is some text";
     post.Text.ShouldBe("This is some text");
 }
Esempio n. 37
0
 public void Can_Get_Set_Title()
 {
     var post = new PostEntity();
     post.Title = "This is a Test";
     post.Title.ShouldBe("This is a Test");
 }
Esempio n. 38
0
 public void Can_Get_Set_Slug()
 {
     var post = new PostEntity();
     post.Slug = "a-clean-url";
     post.Slug.ShouldBe("a-clean-url");
 }
Esempio n. 39
0
 public void Save(PostEntity post)
 {
     repository.SaveOrUpdate(post);
 }