public ActionResult AddCatalogTemplate(CatalogTemplateModel model, GridCommand command)
        {
            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return Content(modelStateErrors.FirstOrDefault());
            }

            var template = new CatalogTemplate
            {
                Name = model.Name,
                ViewPath = this.FileAfterUpload(),
                DisplayOrder = model.DisplayOrder,
                Published = model.Published
            };

            _catalogTemplateService.InsertCatalogTemplate(template);

            return GetCatalogTemplates(command);
        }
        public ActionResult UpdateCatalogTemplate(CatalogTemplateModel model, GridCommand command)
        {
            if (!ModelState.IsValid)
            {
                //display the first model error
                var modelStateErrors = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return Content(modelStateErrors.FirstOrDefault());
            }

            var catalogTemplate = _catalogTemplateService.GetCatalogTemplateById(model.Id);
            if (catalogTemplate == null)
                throw new ArgumentException("No Catalog Template found with the specified id", "id");

            catalogTemplate.Name = model.Name.ToTitle(TitleStyle.FirstCaps);
            catalogTemplate.Published = model.Published;
            catalogTemplate.DisplayOrder = model.DisplayOrder;

            catalogTemplate.ViewPath = this.FileAfterUpload(model.OldViewPath);

            _catalogTemplateService.UpdateCatalogTemplate(catalogTemplate);

            return GetCatalogTemplates(command);
        }
        public ActionResult GetCatalogTemplates(GridCommand command)
        {
            var catalogTemplateList = _catalogTemplateService.GetAllCatalogTemplates(true).OrderBy(x => x.DisplayOrder);

            var gridModel = new GridModel<CatalogTemplateModel>
            {
                Data = catalogTemplateList.Select(template =>
                {
                    var m = new CatalogTemplateModel();

                    m.Id = template.Id;
                    m.Name = template.Name;
                    m.ViewPath = template.ViewPath;
                    m.DisplayOrder = template.DisplayOrder;
                    m.Published = template.Published;

                    return m;
                }),

                Total = catalogTemplateList.Count()
            };

            return new JsonResult()
            {
                Data = gridModel
            };
        }