public ActionResult Create(CatalogModel model, FormCollection formCollection) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogs)) return AccessDeniedView(); if(ModelState.IsValid) { var catalog = new Catalog { Avatar = this.FileAfterUpload(), Name = model.Name, MetaTitle = model.MetaTitle, MetaKeywords = model.MetaKeywords, MetaDescription = model.MetaDescription, Published = model.Published, DisplayOrder = model.DisplayOrder, SEOUrlName = (!string.IsNullOrEmpty(model.SEOUrlName)) ? model.SEOUrlName : model.Name.ToSEName(), }; if (model.TemplateId != 0) catalog.TemplateId = model.TemplateId; if (model.GenericCatalogId != 0) catalog.GenericCatalogId = model.GenericCatalogId; if (model.ParentCatalogId != 0) catalog.ParentCatalogId = model.ParentCatalogId; _catalogService.InsertCatalog(catalog); return RedirectToAction("Edit", new {id = catalog.Id}); } return View(model); }
public ActionResult Remove(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogs)) return AccessDeniedView(); var model = new CatalogModel(_catalogService.GetCatalogById(id)); return View(model); }
public ActionResult Edit(CatalogModel model, int id, FormCollection formCollection, bool saveAndBackList) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogs)) return AccessDeniedView(); if(ModelState.IsValid) { if (TempData["fileUploaded"] != null && model.OldFilePath != null && !string.Empty.Equals(model.OldFilePath)) { var oldIconPath = model.OldFilePath; var dirOldIconPath = Server.MapPath(oldIconPath); if (System.IO.File.Exists(dirOldIconPath) && oldIconPath != DefaultIconUrl) { System.IO.File.Delete(dirOldIconPath); } } var catalog = _catalogService.GetCatalogById(model.Id); catalog.Name = model.Name; catalog.Avatar = this.FileAfterUpload(catalog.Avatar); catalog.MetaTitle = model.MetaTitle; catalog.MetaKeywords = model.MetaKeywords; catalog.MetaDescription = model.MetaDescription; catalog.Published = model.Published; catalog.DisplayOrder = model.DisplayOrder; catalog.SEOUrlName = (!string.IsNullOrEmpty(model.SEOUrlName)) ? model.SEOUrlName : model.Name.ToSEName(); catalog.TemplateId = model.TemplateId; if (model.TemplateId != 0) catalog.TemplateId = model.TemplateId; else catalog.TemplateId = null; if (model.ParentCatalogId != 0) catalog.ParentCatalogId = model.ParentCatalogId; else catalog.ParentCatalogId = null; if (model.GenericCatalogId != 0) catalog.GenericCatalogId = model.GenericCatalogId; else catalog.GenericCatalogId = null; foreach (var record in catalog.CatalogAttributeRecord) { if (String.IsNullOrWhiteSpace(formCollection[record.Attribute.SystemName])) ModelState.AddModelError("","Kiểm tra có để trống không"); record.Value = formCollection[record.Attribute.SystemName]; } _catalogService.UpdateCatalog(catalog); SuccessNotification("Danh mục đã chỉnh sửa thành công!"); return saveAndBackList ? RedirectToAction("Index", new { genericCatalogId = catalog.GenericCatalogId }) : RedirectToAction("Index"); } ViewBag.TemplateId = new SelectList(_catalogTemplateService.GetAllCatalogTemplates(), "Id", "Name", model.TemplateId); return View(model); }
// // GET: /CatalogManager/ public ActionResult Index(int genericCatalogId = 0) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogs)) return AccessDeniedView(); GenericCatalogDDL(); var catalogs = _catalogService.GetCatalogsByGenericCatalogId(genericCatalogId, true, true); var catalogModel = catalogs.Select((entity) => { var model = new CatalogModel(entity); return model; }); return View(catalogModel); }
public ActionResult Edit(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalogs)) return AccessDeniedView(); TemplateDDL(); GenericCatalogDDL(); ParentCatalogDDL(id); var catalog = _catalogService.GetCatalogById(id); _catalogService.CreateRecordForCatalog(catalog); var model = new CatalogModel(catalog); model.CatalogRecordModel .AddRange(catalog.CatalogAttributeRecord .Select(x => new CatalogRecordModel { InputName = x.Attribute.SystemName, Name = x.Attribute.Name, Value = x.Value, Type = x.Attribute.ControlType })); return View(model); }