예제 #1
0
        public async Task <IActionResult> Edit(int id)
        {
            CategoryPostModel categoryPostModel = new CategoryPostModel {
                categories = _categoryRepository.GetAllCategories()
            };
            var user = await _userManager.GetUserAsync(HttpContext.User);

            try
            {
                if (_postRepository.GetPost(id).user == user)
                {
                    categoryPostModel.post = _postRepository.GetPost(id);
                }
                else
                {
                    return(NotFound("404"));
                }
            }
            catch (Exception e)
            {
                return(NotFound("404"));
            }

            return(View(categoryPostModel));
        }
예제 #2
0
        public IActionResult Put([FromBody] CategoryPostModel entityModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //get
            var category = _categoryService.Get(entityModel.Id);

            if (category == null)
            {
                return(RespondFailure());
            }

            category.Name             = entityModel.Name;
            category.ParentCategoryId = entityModel.ParentCategoryId;
            category.Description      = entityModel.Description;
            category.DisplayOrder     = entityModel.DisplayOrder;
            category.Published        = entityModel.Published;
            category.UpdatedOnUtc     = DateTime.Now;
            //save it
            _categoryService.Update(category);

            VerboseReporter.ReportSuccess("Sửa danh mục thành công", "put");
            return(RespondSuccess(category));
        }
예제 #3
0
        public IActionResult AddPost()
        {
            CategoryPostModel categoryPostModel = new CategoryPostModel {
                categories = _categoryRepository.GetAllCategories()
            };

            return(View(categoryPostModel));
        }
        public static Category ToEntity(this CategoryPostModel model)
        {
            Category category = model.Map <Category>();

            category.CreatedOnUtc = category.UpdatedOnUtc = DateTime.Now;

            return(category);
        }
예제 #5
0
        public IActionResult Search(string word)
        {
            ViewBag.Title = "Search Results: " + word;
            CategoryPostModel categoryPostModel = new CategoryPostModel {
                posts = repo.SearchByWord(word), categories = catrepo.GetAllCategories()
            };

            return(View("Index", categoryPostModel));
        }
예제 #6
0
        public IActionResult AddCategory(int Id)
        {
            ViewData["Categories"] = new SelectList(_context.Categories, "Id", "Name");
            CategoryPostModel model = new CategoryPostModel
            {
                TypeId = Id
            };

            return(View(model));
        }
예제 #7
0
        public IActionResult Category(int id)
        {
            CategoryPostModel categoryPostModel = new CategoryPostModel {
                posts = repo.GetByCategory(id), categories = catrepo.GetAllCategories()
            };

            ViewBag.Categoryid      = id;
            categoryPostModel.posts = categoryPostModel.posts.Reverse();
            return(View(categoryPostModel));
        }
        // GET: Category
        public ActionResult Index()
        {
            // List<CategoryBl> servise.GetMyCategories()

            CategoryPostModel model = new CategoryPostModel
            {
                Id    = 1,
                Title = "test"
            };

            return(View("~/Views/Category/MyCategories.cshtml", model));
        }
예제 #9
0
        public IActionResult Error()
        {
            CategoryPostModel categoryPostModel = new CategoryPostModel
            {
                Posts      = _repository.GetAllPosts(),
                Categories = _catrepository.GetAllCategories()
            };

            categoryPostModel.Posts = categoryPostModel.Posts.Reverse();

            return(View(categoryPostModel));
        }
예제 #10
0
        public async Task <IActionResult> DeleteCategory([FromBody] CategoryPostModel postModel)
        {
            try
            {
                await _navigationService.DeleteCategory(postModel.CategoryId);

                return(Json(0));// success
            }
            catch
            {
                return(Json(1));// exception
            }
        }
예제 #11
0
        public async Task <ActionResult <string> > PostCategory([FromBody] CategoryPostModel categoryPostModel)
        {
            Category category = new Category(categoryPostModel.Category);

            // Добавляем переданную категорию.
            _context.Categories.Add(category);

            // Сохраняем изменения в базе данных.
            await _context.SaveChangesAsync();

            // TODO: Разобраться в методе CreatedAtAction.
            return(JsonConvert.SerializeObject(category));
        } // PostCategory.
예제 #12
0
        public ActionResult Index()
        {
            //ViewBag.CatNames = TempData["GetCatNames"];
            ////ViewBag.CatNames = "apple";
            var m = new CategoryPostModel();

            m.CatList   = repCategory.Read().ToList();
            m.PostList  = repPost.Read().ToList();
            m.TopicList = repTopic.Read().ToList();
            // Top = repTopic.Read().ToList();


            return(View(m));
        }
        public Category Create(CategoryPostModel category, User employee)
        {
            int restaurantIdForEmployee = context
                                          .Employees.FirstOrDefault(r => r.UserId == employee.Id).RestaurantId;

            Category categoryToAdd = CategoryPostModel.ToCategory(category);

            categoryToAdd.RestaurantId = restaurantIdForEmployee;

            context.Categories.Add(categoryToAdd);
            context.SaveChanges();

            return(categoryToAdd);
        }
예제 #14
0
        //[Authorize]
        public IActionResult Post([FromBody] CategoryPostModel entityModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var category = entityModel.ToEntity();

            //save it
            _categoryService.Insert(category);

            VerboseReporter.ReportSuccess("Tạo danh mục thành công", "post");
            return(RespondSuccess(entityModel));
        }
예제 #15
0
        // GET: Post/Category/id
        public IActionResult Category(int id)
        {
            CategoryPostModel categoryPostModel = new CategoryPostModel
            {
                Posts      = _repository.GetByCategory(id),
                Categories = _catrepository.GetAllCategories()
            };

            ViewBag.CategoryId = id;

            categoryPostModel.Posts = categoryPostModel.Posts.Reverse();

            return(View(categoryPostModel));
        }
예제 #16
0
 public ActionResult AddCategory([Bind("CategoryId,TypeId")] CategoryPostModel model)
 {
     if (ModelState.IsValid)
     {
         var cat = _context.Categories.SingleOrDefault(x => x.Id == model.CategoryId);
         if (cat != null)
         {
             cat.AttributeType = model.TypeId;
             _context.Categories.Update(cat);
             _context.SaveChanges();
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(model));
 }
예제 #17
0
        public ActionResult PostCatalog(int categoryId)
        {
            var category = _categoryService.GetCategoryById(categoryId);
            var model    = new CategoryPostModel();

            model.Category = category.MapTo <CategoryModel>();

            var allCategories = _categoryService.GetAllCategoriesByParentCategoryId(category.Id);
            var categoryIds   = allCategories.Select(c => c.Id).ToArray();
            var postSetting   = _settingService.GetPostSettings();
            var posts         = _postService.GetAllPost(categoryIds: categoryIds, pageIndex: 0, pageSize: postSetting.PostPageSize);

            model.Post = new PagedSimplePostModel
            {
                PageIndex = 0,
                PageSize  = postSetting.PostPageSize,
                Posts     = posts.Items.MapTo <IList <SimplePostModel> >(),
                Total     = posts.TotalCount
            };
            return(View(model));
        }
예제 #18
0
        public async Task <IActionResult> PostsofUser(string username)
        {
            var user = await _userManager.FindByNameAsync(username);

            if (user == null)
            {
                return(NotFound("404 Sayfa Bulunamadı"));
            }
            var temp = repo.GetByUser(user);

            var userr = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.Title = username + "'s Blogs";
            ViewBag.User  = userr.Id;
            CategoryPostModel categoryPostModel = new CategoryPostModel {
                posts = temp, categories = catrepo.GetAllCategories()
            };

            categoryPostModel.posts = categoryPostModel.posts.Reverse();
            return(View("Index", categoryPostModel));
        }
예제 #19
0
        //[PartialCache("Long")]
        public ActionResult PostHome()
        {
            var menuLinks = _menuLinkService.GetByOption(new List <int> {
                (int)Position.SiderBar
            }, isDisplayHomePage: true);

            if (!menuLinks.IsAny())
            {
                return(HttpNotFound());
            }

            //Convert to localized
            menuLinks = menuLinks.Select(x => x.ToModel());

            var menuParent = menuLinks.Where(x => x.ParentId == null).OrderByDescending(x => x.OrderDisplay);

            var lstPost = new List <Post>();

            foreach (var item in menuParent)
            {
                var iePost = _postService.GetByOption(item.CurrentVirtualId, true);

                if (iePost.IsAny())
                {
                    iePost = iePost.Select(x => x.ToModel());

                    lstPost.AddRange(iePost);
                }
            }

            var categoryPost = new CategoryPostModel
            {
                NumberMenu = menuParent.Count(),
                MenuLinks  = menuParent,
                Posts      = from x in lstPost orderby x.OrderDisplay descending select x
            };

            return(PartialView(categoryPost));
        }
예제 #20
0
        public IActionResult Index()
        {
            /* Category c1 = new Category { name = "Science" };
             * Category c2 = new Category { name = "Space" };
             * Category c3 = new Category { name = "Nature" };
             * Category c4 = new Category { name = "Technology" };
             * Category c5 = new Category { name = "Future" };
             *
             * catrepo.addCategory(c2);
             * catrepo.addCategory(c3);
             * catrepo.addCategory(c4);
             * catrepo.addCategory(c5);
             * catrepo.addCategory(c1);*/



            CategoryPostModel categoryPostModel = new CategoryPostModel {
                posts = repo.GetAllPosts(), categories = catrepo.GetAllCategories()
            };

            categoryPostModel.posts = categoryPostModel.posts.Reverse();

            return(View(categoryPostModel));
        }
예제 #21
0
        public async Task <IActionResult> Edit(CategoryPostModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var post = _mapper.Map <Post>(model.Post);

            // logika perkelti i repo metodus
            if (model.Image == null)
            {
                post.Image = model.CurrentImage;
            }
            else
            {
                post.Image = await _fileManager.SaveImage(model.Image);
            }

            // logika perkelti i repo metodus
            if (post.Id > 0)
            {
                _repository.UpdatePost(post);
            }
            else
            {
                _repository.AddPost(post);
            }


            if (await _repository.SaveChangesAsync())
            {
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        public void Post([FromBody] CategoryPostModel category)
        {
            User employee = this.userService.GetCurrentUser(HttpContext);

            categoryService.Create(category, employee);
        }