예제 #1
0
        public ActionResult EditPostTag(string btnId, string formId, PostTagModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePostTags))
            {
                return(AccessDeniedView());
            }

            var postTag = _postTagService.GetPostTagById(model.Id);

            if (postTag == null)
            {
                //No post tag found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                postTag.Name = model.Name;
                _postTagService.UpdatePostTag(postTag);
                //locales
                UpdateLocales(postTag, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #2
0
        //edit
        public ActionResult EditPostTag(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePostTags))
            {
                return(AccessDeniedView());
            }

            var postTag = _postTagService.GetPostTagById(id);

            if (postTag == null)
            {
                //No post tag found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new PostTagModel
            {
                Id        = postTag.Id,
                Name      = postTag.Name,
                PostCount = _postTagService.GetPostCount(postTag.Id)
            };

            //locales
            AddLocales(_languageService, model.Locales,
                       (locale, languageId) => { locale.Name = postTag.GetLocalized(x => x.Name, languageId, false, false); });

            return(View(model));
        }
예제 #3
0
 protected virtual void UpdateLocales(PostTag postTag, PostTagModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(postTag,
                                                    x => x.Name,
                                                    localized.Name,
                                                    localized.LanguageId);
     }
 }
        public void Update(PostTagModel model)
        {
            var data = Connect_Enttity.PostTags.FirstOrDefault(x => x.ID == model.ID);

            if (data != null)
            {
                data.PostID = model.PostID;
                data.TagID  = model.TagID;

                Connect_Enttity.SaveChanges();
                Dispose();
            }
        }
        public void Create(PostTagModel model)
        {
            var data = Connect_Enttity.PostTags.FirstOrDefault(x => x.ID == model.ID);

            if (data == null)
            {
                var entity = new PostTag();
                entity.PostID = model.PostID;
                entity.TagID  = model.TagID;

                Connect_Enttity.PostTags.Add(entity);
                Connect_Enttity.SaveChanges();
                Dispose();
            }
        }
        public virtual async Task <PostTagModel> PreparePostTagModelAsync(TblPostTags tag)
        {
            PostTagModel result;

            if (tag == null)
            {
                result = new PostTagModel();
            }
            else
            {
                result = tag.Adapt <PostTagModel>();
                await tag.LoadAllLocalizedStringsToModelAsync(result);
            }

            return(result);
        }
예제 #7
0
 public HttpResponseMessage Update(HttpRequestMessage request, PostTagModel PostTagModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var PostTagService = new PostTagService();
             PostTagService.Update(PostTagModel);
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         return response;
     }));
 }
        public virtual async Task <ActionResult> Editor(PostTagModel model, bool?saveAndContinue)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var record   = _postTagsModelFactory.PrepareTblPostTags(model);
            var recordId = model.Id;

            try
            {
                if (model.Id == null)
                {
                    //Add new record
                    recordId = await _postTagsService.AddAsync(record);
                }
                else
                {
                    //Edit record
                    await _postTagsService.UpdateAsync(record);
                }

                await _localizedEntityService.SaveAllLocalizedStringsAsync(record, model);
            }
            catch (Exception e)
            {
                var errorCode = ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Error(e, System.Web.HttpContext.Current));
                ModelState.AddModelError("", string.Format(_localizationService.GetResource("ErrorOnOperation"), e.Message, errorCode));
                return(View(model));
            }

            if (saveAndContinue != null && saveAndContinue.Value)
            {
                return(RedirectToAction("Editor", "ManagePostTags", new { id = recordId }));
            }

            return(Content(@"<script language='javascript' type='text/javascript'>
                                window.close();
                                window.opener.refreshPostTagsGrid();
                             </script>"));
        }
예제 #9
0
        public static PostModel ToModel(this Post.Post post)
        {
            var model = new PostModel
            {
                BlogId    = post.BlogId,
                Id        = post.Id,
                Title     = post.Title,
                Content   = post.Content,
                Deleted   = post.Deleted,
                Published = post.Published
            };

            foreach (var categoryId in post.Categories)
            {
                var postCategoryModel = new PostCategoryModel
                {
                    PostId     = post.Id,
                    CategoryId = categoryId
                };

                model.PostCategories.Add(postCategoryModel);
            }

            foreach (var tag in post.Tags)
            {
                var postTagModel = new PostTagModel
                {
                    PostId  = post.Id,
                    TagName = tag
                };

                model.PostTags.Add(postTagModel);
            }

            return(model);
        }
예제 #10
0
 public void Post([FromBody] PostTagModel pt)
 {
     _tagManager.TagPost(pt.PostId, pt.Tag);
 }
        public virtual TblPostTags PrepareTblPostTags(PostTagModel tag)
        {
            var result = tag.Adapt <TblPostTags>();

            return(result);
        }