Exemplo n.º 1
0
        public ActionResult Details(int id)
        {
            var categoryService = new CategoryService();
            var category        = categoryService.GetCategoryById(new GetCategoryByIdRequest()
            {
                Id = id
            }).Category;

            if (category != null)
            {
                var model = new DetailsCategoryViewModel
                {
                    Title              = category.Title,
                    Description        = category.Description,
                    Summary            = category.Summary,
                    IdUpperCategory    = category.IdUpperCategory,
                    TitleUpperCategory = category.IdUpperCategory.HasValue ? categoryService.GetCategoryById(new GetCategoryByIdRequest()
                    {
                        Id = category.IdUpperCategory.Value
                    }).Category.Title : string.Empty
                };

                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index", "Category"));
            }
        }
 private void CalculatePagesCount(DetailsCategoryViewModel category, int count)
 {
     category.PagesCount = (int)Math.Ceiling((double)count / RestaurantsPerPage);
     if (category.PagesCount == 0)
     {
         category.PagesCount = 1;
     }
 }
Exemplo n.º 3
0
        // GET: Category/Details/5
        public ActionResult Details(int?id, int?subCatNumRows, int?prodNumRows)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Category category = _db.Categories.Find(id);

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

            // get the main category we are looking at list of products
            category.Products = _db.Products.Where(p => p.CategoryId == id).ToList();

            // get the first level of sub category
            category.Children = _db.Categories.Where(c => c.ParentId == id).OrderBy(c => c.Name).ToList();
            // if we got some children
            if (category.Children.Count > 0)
            {
                // get any further sub categories
                category.Children = GetChildren(category.Children, id);
            }

            // create the viewModel
            var viewModel = new DetailsCategoryViewModel();

            // set the viewModels Category
            viewModel.Category = category;

            // if we are a child category (sub-category)
            if (category.ParentId != null)
            {
                viewModel.Parent = _db.Categories.Find(category.ParentId);
            }

            if (category.CreatedBy != null)
            {
                viewModel.CreatedByUsername = _applicationDb.Users.Find(category.CreatedBy).UserName;
            }

            if (category.UpdatedBy != null)
            {
                viewModel.UpdatedByUsername = _applicationDb.Users.Find(category.UpdatedBy).UserName;
            }
            else
            {
                viewModel.UpdatedByUsername = string.Empty;
            }

            // ensure we have a value
            if (subCatNumRows == null)
            {
                // set default of X per page (we can choose something suitable 0 gets all)
                subCatNumRows = 5;
            }

            // ensure we have a value
            if (prodNumRows == null)
            {
                // set default of X per page (we can choose something suitable 0 gets all)
                prodNumRows = 5;
            }

            viewModel.SubCategoryRowsPerCategory = Convert.ToInt32(subCatNumRows);
            viewModel.ProductRowsPerCategory     = Convert.ToInt32(prodNumRows);
            viewModel.RowOptions = Models.Constants.SMALL_GRID_ROW_OPTIONS;

            return(View(viewModel));
        }