Пример #1
0
        public async Task <ActionResult> UpdatePostBusinessAsync([FromForm] ReqUpdatePostBusiness reqData)
        {
            var result = await _postLogic.UpdatePostBusinessAsync(reqData);

            return(Ok(new BaseResponse(result)));
        }
Пример #2
0
        /*
         * Update post
         */
        public async Task <ResUpdatePostBusiness> UpdatePostBusinessAsync(ReqUpdatePostBusiness reqUpdatePostBusiness)
        {
            try
            {
                ResUpdatePostBusiness resUpdatePostBusiness = new ResUpdatePostBusiness();
                _logger.LogInformation("Update post business");
                if (reqUpdatePostBusiness != null)
                {
                    Post postData = _uow.GetRepository <Post>()
                                    .GetWithRelated(a => a.Id == reqUpdatePostBusiness.Id, null, "Seo")
                                    .FirstOrDefault();

                    postData.Name       = reqUpdatePostBusiness.Name;
                    postData.Content    = reqUpdatePostBusiness.Content;
                    postData.CategoryId = reqUpdatePostBusiness.CategoryId;

                    postData.Seo.SeoTitle       = reqUpdatePostBusiness.SeoTitle;
                    postData.Seo.SeoKeys        = reqUpdatePostBusiness.SeoKeys;
                    postData.Seo.SeoDescription = reqUpdatePostBusiness.SeoDescription;

                    // Updated Tag list (ObjectTag)
                    _objectTagLogic.UpdateObjectTagsBusinessAsync(
                        reqUpdatePostBusiness.TagList,
                        reqUpdatePostBusiness.TagListHidden,
                        reqUpdatePostBusiness.Id,
                        reqUpdatePostBusiness.PostType,
                        out List <ObjectTag> objectTags
                        );
                    postData.ObjectTags = objectTags;

                    //Seo seoData = postData.Seo;
                    //ReqUpdateSeo reqUpdateSeo = new ReqUpdateSeo
                    //{
                    //    Id = seoData.Id,
                    //    ObjectId = reqUpdatePostBusiness.Id,
                    //    SeoTitle = reqUpdatePostBusiness.SeoTitle,
                    //    SeoKeys = reqUpdatePostBusiness.SeoKeys,
                    //    SeoDescription = reqUpdatePostBusiness.SeoDescription
                    //};

                    //// Update data for post.
                    //ReqUpdatePost reqUpdatePost = new ReqUpdatePost
                    //{
                    //    Id = reqUpdatePostBusiness.Id,
                    //    Name = reqUpdatePostBusiness.Name,
                    //    Content = reqUpdatePostBusiness.Content,
                    //    CategoryId = reqUpdatePostBusiness.CategoryId,
                    //    File = reqUpdatePostBusiness.File
                    //};
                    //Task<Post> postUpdated = this.UpdatePostAsync(reqUpdatePost);

                    // Update Object Media (feature image)
                    // Task<UpdatedPostBusinessObjectMediaVM> objectMediaUpdated = _objectMediaLogic.ObjectMediaUpdatePostBusinessAsync(reqUpdatePostBusiness.File, reqUpdatePostBusiness.Id, reqUpdatePostBusiness.PostType, "thumbnail");


                    //// Update seo data
                    //Seo seoData = postData.Seo;
                    //ReqUpdateSeo reqUpdateSeo = new ReqUpdateSeo
                    //{
                    //    Id = seoData.Id,
                    //    ObjectId = reqUpdatePostBusiness.Id,
                    //    SeoTitle = reqUpdatePostBusiness.SeoTitle,
                    //    SeoKeys = reqUpdatePostBusiness.SeoKeys,
                    //    SeoDescription = reqUpdatePostBusiness.SeoDescription
                    //};
                    //Task<Seo> seoUpdated = _seoLogic.UpdateSeoAsync(reqUpdateSeo);

                    //await Task.WhenAll(postUpdated, seoUpdated, objectMediaUpdated, objectTagUpdated);

                    //resUpdatePostBusiness.PostUpdated = postUpdated.Result;
                    //resUpdatePostBusiness.SeoUpdated = seoUpdated.Result;
                    //resUpdatePostBusiness.ObjectTagUpdated = objectTagUpdated.Result;
                    //resUpdatePostBusiness.ObjectMediaUpdated = objectMediaUpdated.Result;

                    _uow.GetRepository <Post>().Update(postData);
                    _uow.SaveChanges();
                }

                return(resUpdatePostBusiness);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message.ToString());
                throw ex;
            }
        }