コード例 #1
0
        public ActionResult GetById(int id)
        {
            var app            = new ServiceReference.ContractClient();
            var categoryClient = app.GetCategoryById(id);
            var model          = new CategoryViewModel(categoryClient);

            //var model = new Category
            //{
            //    Id = categoryClient.Id,
            //    Name = categoryClient.Name,
            //    Description = categoryClient.Description,
            //    Level = categoryClient.Level,
            //    ParentId = categoryClient.ParentId,
            //    Enabled = categoryClient.Enabled

            //};
            return(View(model));
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            var app            = new ServiceReference.ContractClient();
            var categoryClient = app.GetCategoryById(id);

            var model = new CategoryViewModel
            {
                Id          = categoryClient.Id,
                Name        = categoryClient.Name,
                Description = categoryClient.Description,
                Level       = categoryClient.Level,
                ParentId    = categoryClient.ParentId,
                Enabled     = categoryClient.Enabled
            };
            //obtenemso todas las categorias
            var categoriesClient = app.GetAllCategories();

            //de todas las categorias, tomamos solo las padre y por cada una generamos un categoryviewmodel
            var completeModel = categoriesClient.Where(x => x.Level == 0).Select(x => new CategoryViewModel(x)).ToList();

            model.ParentCategories = completeModel;
            return(View(model));
        }