예제 #1
0
        public ActionResult AddGenericCatalogTemplate(GenericCatalogTemplateModel 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 GenericCatalogTemplate
            {
                Name = model.Name,
                ViewPath = this.FileAfterUpload(),
                DisplayOrder = model.DisplayOrder,
                Published = model.Published
            };

            _genericCatalogTemplateService.InsertGenericCatalogTemplate(template);

            return GetGenericCatalogTemplates(command);
        }
예제 #2
0
        public ActionResult UpdateGenericCatalogTemplate(GenericCatalogTemplateModel 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 genericCatalogTemplate = _genericCatalogTemplateService.GetGenericCatalogTemplateById(model.Id);
            if (genericCatalogTemplate == null)
                throw new ArgumentException("No Generic Catalog Template found with the specified id", "id");

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

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

            _genericCatalogTemplateService.UpdateGenericCatalogTemplate(genericCatalogTemplate);

            return GetGenericCatalogTemplates(command);
        }
예제 #3
0
        public ActionResult GetGenericCatalogTemplates(GridCommand command)
        {
            var genericCatalogTemplateList = _genericCatalogTemplateService.GetAllGenericCatalogTemplates(true);

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

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

                    return m;
                }),

                Total = genericCatalogTemplateList.Count
            };

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