protected virtual void PrepareDepartmentModel(DepartmentModel model, Department department) { if (model == null) throw new ArgumentNullException("model"); var departments = _departmentService.GetAll(); model.AvailableDepartments.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Department.NotParentDepartment"), Value = "0" }); foreach (var d in departments) model.AvailableDepartments.Add(new SelectListItem { Text = d.Name, Value = d.Id.ToString(), Selected = department == null ? false : d.Id == department.ParentId }); var stores = _storeService.GetAllStores(); model.AvailableStores.Add(new SelectListItem { Text = _localizationService.GetResource("Admin.Common.Select"), Value = "0" }); foreach (var d in stores) { model.AvailableStores.Add(new SelectListItem { Value = d.Id.ToString(), Text = d.Name, Selected = department != null ? model.StoreId == d.Id : false }); } }
public ActionResult Create(DepartmentModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageUsers)) return AccessDeniedView(); if (ModelState.IsValid) { var department = model.ToEntity(); _departmentService.Insert(department); //activity log //_customerActivityService.InsertActivity("AddNewDepartment", _localizationService.GetResource("ActivityLog.AddNewDepartment"), department.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.Departments.Added")); return continueEditing ? RedirectToAction("Edit", new { id = department.Id }) : RedirectToAction("List"); } PrepareDepartmentModel(model, null); //If we got this far, something failed, redisplay form return View(model); }
public ActionResult Edit(DepartmentModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageUsers)) return AccessDeniedView(); var department = _departmentService.GetById(model.Id); if (department == null) //No product attribute found with the specified id return RedirectToAction("List"); if (ModelState.IsValid) { department = model.ToEntity(department); _departmentService.Update(department); //activity log //_customerActivityService.InsertActivity("EditDepartment", _localizationService.GetResource("ActivityLog.EditDepartment"), department.Name); SuccessNotification(_localizationService.GetResource("Admin.Departments.Updated")); return continueEditing ? RedirectToAction("Edit", department.Id) : RedirectToAction("List"); } PrepareDepartmentModel(model, department); //If we got this far, something failed, redisplay form return View(model); }
//create public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageUsers)) return AccessDeniedView(); var model = new DepartmentModel(); model.DisplayOrder = 0; model.Deleted = false; PrepareDepartmentModel(model, null); return View(model); }