Esempio n. 1
0
        public async Task <int> Update(TopicPost topic)
        {
            var cmd = QueriesCreatingHelper.CreateQueryUpdate(topic);
            var rs  = await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection);

            return(rs == 0 ? -1 : 0);
        }
Esempio n. 2
0
        public async Task <int> Add(TopicPost topic)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(topic);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 3
0
 public HttpResponseMessage Create(TopicPost topic)
 {
     return(ProcessPost(() =>
     {
         var instance = topic.ToModel();
         createGroupCommand.Execute(instance);
         return ResourceLocation.OfTopic(instance.Id.Value);
     }));
 }
Esempio n. 4
0
        public Topic CreateTopicWithoutGroup(string name, string description = "")
        {
            var topicPost = new TopicPost {
                Name = name, Description = description
            };
            var location = restClient.Post(Operations.Topics, topicPost);
            var topic    = restClient.Get <Facade.Topic>(location.ToString());

            return(topic == null ? null : new Topic(topic, restClient));
        }
Esempio n. 5
0
        public Topic CreateTopic(string name, string description = "")
        {
            var topicPost = new TopicPost {
                Name = name, Description = description, GroupId = (Identity)Id
            };
            var location     = restClient.Post(group.GetLinkForRelation("Create Topic"), topicPost);
            var topicCreated = restClient.Get <Facade.Topic>(location.ToString());

            return(new Topic(topicCreated, this, restClient));
        }
        public TopicPostViewModel GetTopicPostById(int topicId)
        {
            TopicPostViewModel model = new TopicPostViewModel();

            try
            {
                TopicPost topicPost = PostManager.GetTopicById(topicId);
                model = ObjectMapper.Map <Model.Entities.TopicPost, TopicPostViewModel>(topicPost);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing);
            }
            return(model);
        }
        public int AddTopicPost(TopicPostViewModel topicPost)
        {
            try
            {
                TopicPost _topicPost = ObjectMapper.Map <TopicPostViewModel, TopicPost>(topicPost);

                TopicPost newTopicPost = PostManager.Add(_topicPost);
                return(newTopicPost.Id);
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing);
                return(0);
            }
        }
        /// <summary>
        /// Gets the topic post by topic post id.
        /// </summary>
        /// <param name="topicId">The topic id.</param>
        /// <returns></returns>
        public Model.Entities.TopicPost GetTopicPostByTopicPostId(int topicId)
        {
            try
            {
                TopicPost obj = this.Context.Set <TopicPost>().Where(p => p.Id == topicId).FirstOrDefault();


                return(ObjectMapper.Map <TopicPost, Model.Entities.TopicPost>(obj));
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex, PolicyNameType.ExceptionShielding);
            }

            return(null);
        }
Esempio n. 9
0
        public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken)
        {
            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Post        = CreateBuild(request.Post, request.LoginSession);
                        request.Post.IsUsed = true;
                        var postId = await postRepository.AddAsync(request.Post);

                        if (request.Post.Topics.Count() != 0)
                        {
                            var topicPost = new TopicPost();
                            foreach (var topicItems in request.Post.Topics)
                            {
                                topicPost.PostId  = postId;
                                topicPost.TopicId = topicItems.Id;
                                rs = (await topicPostHomepageRepository.Add(topicPost)) > 0 ? 0 : -1;
                            }
                        }
                        else
                        {
                            var topicPost = new TopicPost()
                            {
                                PostId  = postId,
                                TopicId = 1
                            };
                            rs = (await topicPostHomepageRepository.Add(topicPost)) > 0 ? 0 : -1;
                        }


                        // languages
                        foreach (var item in request.Post.PostLanguages)
                        {
                            item.PostId = postId;
                            rs          = (await postRepository.AddOrUpdateLanguage(item)) > 0 ? 0 : -1;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                        }
                    }
                }
            }

            return(rs);
        }
Esempio n. 10
0
 public AddCommand(TopicPost post)
 {
     this.TopicPost = post;
 }
Esempio n. 11
0
        public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.Post == null || request.Post.Id == 0)
            {
                throw new BusinessException("Post.NotExisted");
            }

            var post = (await postQueries.GetPostById(request.Post.Id));

            if (post == null)
            {
                throw new BusinessException("Post.NotExisted");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        //Update table Post
                        request.Post = UpdateBuild(request.Post, request.LoginSession);
                        rs           = await postRepository.UpdateAsync(request.Post);

                        //Get all topicpost of post update
                        var topicPosts = await topicPostHomepageQueries.GetsByPost(request.Post.Id);

                        if (topicPosts == null)
                        {
                            return(-1);
                        }

                        //delete all topicpost of post  update by id
                        foreach (var tpItem in topicPosts)
                        {
                            rs = await topicPostHomepageRepository.Delete(tpItem.Id);
                        }

                        //insert new topicpost of post update
                        if (request.Post.Topics.Count() != 0)
                        {
                            var topicPost = new TopicPost();
                            foreach (var topicItems in request.Post.Topics)
                            {
                                topicPost.PostId  = request.Post.Id;
                                topicPost.TopicId = topicItems.Id;
                                rs = (await topicPostHomepageRepository.Add(topicPost)) > 0 ? 0 : -1;
                            }
                        }
                        else
                        {
                            var topicPost = new TopicPost()
                            {
                                PostId  = request.Post.Id,
                                TopicId = 1
                            };
                            rs = (await topicPostHomepageRepository.Add(topicPost)) > 0 ? 0 : -1;
                        }

                        // languages
                        foreach (var item in request.Post.PostLanguages)
                        {
                            item.PostId = request.Post.Id;
                            rs          = (await postRepository.AddOrUpdateLanguage(item)) > 0 ?0 : -1;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                        }
                    }
                }
            }

            return(rs);
        }
Esempio n. 12
0
 public UpdateCommand(TopicPost post)
 {
     this.TopicPost = post;
 }