public virtual IActionResult Create(CustomerRoleModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var customerRole = model.ToEntity <CustomerRole>(); _customerService.InsertCustomerRole(customerRole); //activity log _customerActivityService.InsertActivity("AddNewCustomerRole", string.Format(_localizationService.GetResource("ActivityLog.AddNewCustomerRole"), customerRole.Name), customerRole); SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerRoles.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } //prepare model model = _customerRoleModelFactory.PrepareCustomerRoleModel(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
protected List <SelectListItem> GetTaxDisplayTypesList(CustomerRoleModel model) { var list = new List <SelectListItem>(); if (model.TaxDisplayType.HasValue) { list.Insert(0, new SelectListItem { Text = T("Enums.Smartstore.Core.Domain.Tax.TaxDisplayType.IncludingTax"), Value = "0", Selected = (TaxDisplayType)model.TaxDisplayType.Value == TaxDisplayType.IncludingTax }); list.Insert(1, new SelectListItem { Text = T("Enums.Smartstore.Core.Domain.Tax.TaxDisplayType.ExcludingTax"), Value = "10", Selected = (TaxDisplayType)model.TaxDisplayType.Value == TaxDisplayType.ExcludingTax }); } else { list.Insert(0, new SelectListItem { Text = T("Enums.Smartstore.Core.Domain.Tax.TaxDisplayType.IncludingTax"), Value = "0" }); list.Insert(1, new SelectListItem { Text = T("Enums.Smartstore.Core.Domain.Tax.TaxDisplayType.ExcludingTax"), Value = "10" }); } return(list); }
private void PrepareCustomerRoleModel(CustomerRoleModel model) { var parentRoles = _roleService.GetAllRoles(showHidden: true, parentIds: new List <int> { 0 } ); if (model == null) { model = new CustomerRoleModel(); } model.AvailableParentRole.Add(new SelectListItem { Selected = model.ParentId == 0, Text = "顶级角色", Value = "0", }); foreach (var item in parentRoles.Items) { model.AvailableParentRole.Add(new SelectListItem { Selected = model.ParentId == item.Id, Text = item.RoleName, Value = item.Id.ToString(), }); } }
/// <summary> /// 新增页面 /// </summary> /// <returns></returns> public ActionResult Create() { var model = new CustomerRoleModel(); PrepareCustomerRoleModel(model); return(View(model)); }
public virtual async Task <IActionResult> Edit(CustomerRoleModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCustomers) || !await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAcl)) { return(AccessDeniedView()); } //try to get a customer role with the specified id var customerRole = await _customerService.GetCustomerRoleByIdAsync(model.Id); if (customerRole == null) { return(RedirectToAction("List")); } try { if (ModelState.IsValid) { if (customerRole.IsSystemRole && !model.Active) { throw new NopException(await _localizationService.GetResourceAsync("Admin.Customers.CustomerRoles.Fields.Active.CantEditSystem")); } if (customerRole.IsSystemRole && !customerRole.SystemName.Equals(model.SystemName, StringComparison.InvariantCultureIgnoreCase)) { throw new NopException(await _localizationService.GetResourceAsync("Admin.Customers.CustomerRoles.Fields.SystemName.CantEditSystem")); } if (NopCustomerDefaults.RegisteredRoleName.Equals(customerRole.SystemName, StringComparison.InvariantCultureIgnoreCase) && model.PurchasedWithProductId > 0) { throw new NopException(await _localizationService.GetResourceAsync("Admin.Customers.CustomerRoles.Fields.PurchasedWithProduct.Registered")); } customerRole = model.ToEntity(customerRole); await _customerService.UpdateCustomerRoleAsync(customerRole); //activity log await _customerActivityService.InsertActivityAsync("EditCustomerRole", string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditCustomerRole"), customerRole.Name), customerRole); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Customers.CustomerRoles.Updated")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } //prepare model model = await _customerRoleModelFactory.PrepareCustomerRoleModelAsync(model, customerRole, true); //if we got this far, something failed, redisplay form return(View(model)); } catch (Exception exc) { await _notificationService.ErrorNotificationAsync(exc); return(RedirectToAction("Edit", new { id = customerRole.Id })); } }
public ActionResult Create() { var model = new CustomerRoleModel(); model.IsActive = true; return(View(model)); }
public virtual CustomerRoleModel PrepareCustomerRoleModel() { var model = new CustomerRoleModel(); //default values model.Active = true; return(model); }
public ActionResult CustomerRoles(CustomerRoleModel model, string submitButton) { //check the other submit buttons and act on them, or continue switch (submitButton) { case "Cancel": return(RedirectToAction("Index", "Users")); } int userID = (new UserFactory()).GetUserId(model.Username); //remove all caching table data for this user (new UserCustomerAccessManager()).ClearCustomerAccess(userID); //first, we HAVE to loop horugh and remove all the groups before we add. This way when adding maintneance groups, the _maint group gtes added correctly. foreach (var customerRole in model.CustomerRoles) { //get a auth manager for this customer var authMan = new AuthorizationManager(customerRole.CustomerInternalName); //remove the user from all the groups in this customer authMan.RemoveMemberGroups(model.Username); //remove them from maintenance as well. this is the only place we do this since this is the only place they can be added to a maint gorup without being set as a technician. //IE - only applies to administrative users. authMan.RemoveMemberFromMaintenanceGroup(model.Username); //now we have to clear the menu cache HttpContext.Cache.Remove("__PemsMenu" + customerRole.CustomerInternalName.Trim() + model.Username.Trim()); } //now add the correct roles foreach (var customerRole in model.CustomerRoles) { // now add them to the specific group for this store they will have access to //only need to do this when there is a valid group name (not empty) if (customerRole.CurrentRole != (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.DropDownDefault, "Select One")) { var authMan = new AuthorizationManager(customerRole.CustomerInternalName); authMan.AddGroupMember(customerRole.CurrentRole, model.Username, false); //also update the caching table - they have access to one role, so they have access to the site. authMan.AddCustomerAccess(userID); //we also have to add them to the _maintenance Role if this customer is a maintenance group //IE - we are giving any duncan admin users (which are the only ones using this page) //that have any access to this maintenance group a _maintenance role as well, so they can log into the handheld. //have to setup the city first customerRole.Customer = new PemsCity(customerRole.CustomerInternalName); if (customerRole.Customer.CustomerType == CustomerProfileType.MaintenanceGroup) { (new TechnicianFactory()).AddAdminTechnicianToMaintenanceGroup(model.Username, customerRole.Customer, userID); } } } return(RedirectToAction("Index", "Users")); }
public virtual CustomerRole InsertCustomerRoleModel(CustomerRoleModel model) { var customerRole = model.ToEntity(); _customerService.InsertCustomerRole(customerRole); //activity log _customerActivityService.InsertActivity("AddNewCustomerRole", customerRole.Id, _localizationService.GetResource("ActivityLog.AddNewCustomerRole"), customerRole.Name); return(customerRole); }
public ActionResult Edit(CustomerRoleModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedView()); } var customerRole = _customerService.GetCustomerRoleById(model.Id); if (customerRole == null) { //No customer role found with the specified id return(RedirectToAction("List")); } try { if (ModelState.IsValid) { if (customerRole.IsSystemRole && !model.Active) { throw new NopException( _localizationService.GetResource( "Admin.Customers.CustomerRoles.Fields.Active.CantEditSystem")); } if (customerRole.IsSystemRole && !customerRole.SystemName.Equals(model.SystemName, StringComparison.InvariantCultureIgnoreCase)) { throw new NopException( _localizationService.GetResource( "Admin.Customers.CustomerRoles.Fields.SystemName.CantEditSystem")); } customerRole = model.ToEntity(customerRole); _customerService.UpdateCustomerRole(customerRole); //activity log _customerActivityService.InsertActivity("EditCustomerRole", _localizationService.GetResource("ActivityLog.EditCustomerRole"), customerRole.Name); SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerRoles.Updated")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); } catch (Exception exc) { ErrorNotification(exc); return(RedirectToAction("Edit", new { id = customerRole.Id })); } }
public IActionResult Create(CustomerRoleModel model, bool continueEditing) { if (ModelState.IsValid) { var customerRole = _customerRoleViewModelService.InsertCustomerRoleModel(model); SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerRoles.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create() { var model = new CustomerRoleModel { Active = true }; PrepareModel(model, null); return(View(model)); }
public ActionResult Create() { var model = new CustomerRoleModel { Active = true }; model.TaxDisplayTypes = GetTaxDisplayTypesList(model); return(View(model)); }
protected virtual void PrepareCustomerRoleModel(CustomerRoleModel model, CustomerRole customerRole) { if (customerRole != null) { var product = _productService.GetProductById(customerRole.PurchasedWithProductId); if (product != null) { model.PurchasedWithProductName = product.Name; } } model.TaxDisplayTypeValues = _taxSettings.TaxDisplayType.ToSelectList(); }
public ActionResult Create(CustomerRoleModel model, bool continueEditing) { if (ModelState.IsValid) { model.IsActive = true; var customerRole = model.ToEntity(); _customerService.InsertCustomerRole(customerRole); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Edit(CustomerRoleModel model, bool continueEditing) { var customerRole = _customerService.GetCustomerRoleById(model.Id); if (customerRole == null) { //No customer role found with the specified id return(RedirectToAction("List")); } customerRole = model.ToEntity(customerRole); _customerService.UpdateCustomerRole(customerRole); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); }
public ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedView()); } var model = new CustomerRoleModel(); //default values model.Active = true; return(View(model)); }
private void PrepareModel(CustomerRoleModel model, CustomerRole role) { if (role != null) { model.SelectedRuleSetIds = role.RuleSets.Select(x => x.Id).ToArray(); } model.TaxDisplayTypes = model.TaxDisplayType.HasValue ? ((TaxDisplayType)model.TaxDisplayType.Value).ToSelectList().ToList() : TaxDisplayType.IncludingTax.ToSelectList(false).ToList(); model.GridPageSize = _adminAreaSettings.GridPageSize; model.UsernamesEnabled = _customerSettings.CustomerLoginType != CustomerLoginType.Email; }
public ActionResult Create(CustomerRoleModel model, bool continueEditing) { if (ModelState.IsValid) { var customerRole = model.ToEntity(); _customerService.InsertCustomerRole(customerRole); _customerActivityService.InsertActivity("AddNewCustomerRole", T("ActivityLog.AddNewCustomerRole"), customerRole.Name); NotifySuccess(T("Admin.Customers.CustomerRoles.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } return(View(model)); }
public virtual ActionResult Create() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedView()); } var model = new CustomerRoleModel { //设置默认启用 Active = true }; return(View(model)); }
/// <summary> /// Prepare customer role model /// </summary> /// <param name="model">Customer role model</param> /// <param name="customerRole">Customer role</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Customer role model</returns> public virtual CustomerRoleModel PrepareCustomerRoleModel(CustomerRoleModel model, CustomerRole customerRole, bool excludeProperties = false) { if (customerRole != null) { //fill in model values from the entity model = model ?? customerRole.ToModel <CustomerRoleModel>(); } //set default values for the new model if (customerRole == null) { model.Active = true; } return(model); }
public virtual ActionResult Edit(CustomerRoleModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedView()); } var customerRole = _customerService.GetCustomerRoleById(model.Id); if (customerRole == null) { return(RedirectToAction("List")); } try { if (ModelState.IsValid) { //确保系统角色不被禁用 if (customerRole.IsSystemRole && !model.Active) { throw new SiteException(_localizationService.GetResource("Admin.Customers.CustomerRoles.Fields.Active.CantEditSystem")); } //确保系统角色系统名不被修改 if (customerRole.IsSystemRole && !customerRole.SystemName.Equals(model.SystemName, StringComparison.InvariantCultureIgnoreCase)) { throw new SiteException(_localizationService.GetResource("Admin.Customers.CustomerRoles.Fields.SystemName.CantEditSystem")); } customerRole = model.ToEntity(customerRole); _customerService.UpdateCustomerRole(customerRole); _customerActivityService.InsertActivity("EditCustomerRole", _localizationService.GetResource("ActivityLog.EditCustomerRole"), customerRole.Name); SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerRoles.Updated")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } return(View(model)); } catch (Exception exc) { ErrorNotification(exc); return(RedirectToAction("Edit", new { id = customerRole.Id })); } }
public ActionResult Edit(CustomerRoleModel model, bool continueEditing) { if (ModelState.IsValid) { var customerRole = model.MapTo <CustomerRole>(); _roleService.UpdateCustomerRole(customerRole); if (continueEditing) { return(RedirectToAction("Edit", new { id = customerRole.Id })); } return(RedirectToAction("List")); } PrepareCustomerRoleModel(model); return(View(model)); }
public async Task <IActionResult> Edit(CustomerRoleModel model, bool continueEditing) { var customerRole = await _customerService.GetCustomerRoleById(model.Id); if (customerRole == null) { //No customer role found with the specified id return(RedirectToAction("List")); } try { if (ModelState.IsValid) { if (customerRole.IsSystemRole && !model.Active) { throw new GrandException(_localizationService.GetResource("Admin.Customers.CustomerRoles.Fields.Active.CantEditSystem")); } if (customerRole.IsSystemRole && !customerRole.SystemName.Equals(model.SystemName, StringComparison.OrdinalIgnoreCase)) { throw new GrandException(_localizationService.GetResource("Admin.Customers.CustomerRoles.Fields.SystemName.CantEditSystem")); } if (SystemCustomerRoleNames.Registered.Equals(customerRole.SystemName, StringComparison.OrdinalIgnoreCase) && !String.IsNullOrEmpty(model.PurchasedWithProductId)) { throw new GrandException(_localizationService.GetResource("Admin.Customers.CustomerRoles.Fields.PurchasedWithProduct.Registered")); } customerRole = await _customerRoleViewModelService.UpdateCustomerRoleModel(customerRole, model); SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerRoles.Updated")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); } catch (Exception exc) { ErrorNotification(exc); return(RedirectToAction("Edit", new { id = customerRole.Id })); } }
/// <summary> /// Prepare customer role model /// </summary> /// <param name="model">Customer role model</param> /// <param name="customerRole">Customer role</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Customer role model</returns> public virtual CustomerRoleModel PrepareCustomerRoleModel(CustomerRoleModel model, CustomerRole customerRole, bool excludeProperties = false) { if (customerRole != null) { //fill in model values from the entity model = model ?? customerRole.ToModel<CustomerRoleModel>(); model.PurchasedWithProductName = _productService.GetProductById(customerRole.PurchasedWithProductId)?.Name; } //set default values for the new model if (customerRole == null) model.Active = true; //prepare available tax display types _baseAdminModelFactory.PrepareTaxDisplayTypes(model.TaxDisplayTypeValues, false); return model; }
public ActionResult Create(CustomerRoleModel model, bool continueEditing) { if (ModelState.IsValid) { //这里就是页面实体映射的关键,我可以把页面的实体转换为数据库的实体在进行操作 //但是还需要一小步在web项目中的App_Start文件夹中有个Blog_SolutionWebModule类,我们要注意下 //去看看就知道了 var entity = model.MapTo <CustomerRole>(); _roleService.InsertCustomerRole(entity); if (continueEditing) { return(RedirectToAction("Edit", new { id = entity.Id })); } return(RedirectToAction("List")); } PrepareCustomerRoleModel(model); return(View(model)); }
public virtual ActionResult Create(CustomerRoleModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var customerRole = model.ToEntity(); _customerService.InsertCustomerRole(customerRole); _customerActivityService.InsertActivity("AddNewCustomerRole", _localizationService.GetResource("ActivityLog.AddNewCustomerRole"), customerRole.Name); SuccessNotification(_localizationService.GetResource("Admin.Customers.CustomerRoles.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = customerRole.Id }) : RedirectToAction("List")); } return(View(model)); }
// GET: UserRoles/Create public IActionResult Create() { if (!(bool)SharedData.isUserRoleMenuAccessible) { return(AccessDeniedView()); } ViewBag.FormName = "User Role"; //permissions //if (SharedData.isUserRolesMenuAccessible == false) // return AccessDeniedView(); var model = new CustomerRoleModel(); //default value model.Active = true; //default value return(View(model)); }
private void PrepareModel(CustomerRoleModel model, CustomerRole role) { if (role != null) { model.SelectedRuleSetIds = role.RuleSets.Select(x => x.Id).ToArray(); model.ShowRuleApplyButton = model.SelectedRuleSetIds.Any(); if (!model.ShowRuleApplyButton) { var customerRoleMappingQuery = _customerService.GetCustomerRoleMappings(null, new[] { role.Id }, true, 0, int.MaxValue, false).SourceQuery; model.ShowRuleApplyButton = customerRoleMappingQuery.Any(); } } model.TaxDisplayTypes = model.TaxDisplayType.HasValue ? ((TaxDisplayType)model.TaxDisplayType.Value).ToSelectList().ToList() : TaxDisplayType.IncludingTax.ToSelectList(false).ToList(); model.GridPageSize = _adminAreaSettings.GridPageSize; model.UsernamesEnabled = _customerSettings.CustomerLoginType != CustomerLoginType.Email; }
//Create,List,Edit,Delete (Get/Post)Methods #region Methods // GET: UserRoles public IActionResult Index() { //PageSize //var report = SharedData.UserRoleReport; //if (report != null) //{ // SharedData.RowCount = report.RowCount; // SharedData.ReportName = "UserRole"; //} //else //{ // SharedData.RowCount = 10; // SharedData.ReportName = "UserRole"; //} //form Name ViewBag.FormName = "User Roles "; //permissions if (SharedData.isAccessAdminPanelMenuAccessible == false) { return(AccessDeniedView()); } var model = new CustomerRoleListModel(); var customerRole = _customerService.GetAllCustomerRoles().Select(x => { var cmodel = new CustomerRoleModel() { Id = x.Id, Name = x.Name, Description = x.Description, Active = x.Active //ignore address for list view (performance optimization) }; return(cmodel); }) .ToList(); model.ListCustomerRole = customerRole; return(View(model)); }