예제 #1
0
        public ActionResult Edit(CategoryModel model)
        {
            if (ModelState.IsValid)
            {
                var category = categoryService.GetById(model.Id);
                category.Name     = model.Name;
                category.IsActive = model.IsActive;
                categoryService.UpdateCategory(category);

                var urlRecord = urlService.GetByEntity(category.Id, EntityType.Category);
                if (urlRecord == null)
                {
                    urlRecord = new UrlRecord
                    {
                        EntityId   = category.Id,
                        UniqueUrl  = model.Url,
                        EntityType = EntityType.Category
                    };
                    urlService.InsertUrl(urlRecord);
                }
                else
                {
                    urlRecord.UniqueUrl = model.Url;
                    urlService.UpdateUrl(urlRecord);
                }

                return(RedirectToAction("Edit", new { Id = model.Id }));
            }

            ViewBag.Categories = categoryService.GetActives();
            return(View(model));
        }
예제 #2
0
        public ActionResult Edit(PostModel model)
        {
            if (ModelState.IsValid)
            {
                var post = postService.GetById(model.Id);
                post.Title        = model.Title;
                post.CategoryId   = model.CategoryId;
                post.Description  = model.Description;
                post.PicturePath  = model.PicturePath;
                post.ShortContent = model.ShortContent;
                post.FullContent  = model.FullContent;
                post.IsActive     = model.IsActive;
                post.AllowComment = model.AllowComment;
                post.UpdateDate   = DateTime.Now;
                postService.UpdatePost(post);

                var urlRecord = urlService.GetByEntity(post.Id, EntityType.Post);
                if (urlRecord == null)
                {
                    urlRecord = new UrlRecord
                    {
                        EntityId   = post.Id,
                        UniqueUrl  = model.Url,
                        EntityType = EntityType.Post
                    };
                    urlService.InsertUrl(urlRecord);
                }
                else
                {
                    urlRecord.UniqueUrl = model.Url;
                    urlService.UpdateUrl(urlRecord);
                }

                return(RedirectToAction("Edit", new { Id = model.Id }));
            }

            ViewBag.Categories = categoryService.GetActives();
            return(View(model));
        }