public virtual IActionResult AddCustomer(CustomerUnitModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageUnit)) { return(AccessDeniedView()); } var item = _unitService.GetUnitById(model.UnitId); var chk = _unitService.insertCustomerUnit(model.UnitId, model.CustomerId); if (chk) { //activity log _customerActivityService.InsertActivity("AddNewCustomerUnit", string.Format(_localizationService.GetResource("ActivityLog.AddNewCustomerUnit"), item.Id), item); return(this.JsonSuccessMessage(_localizationService.GetResource("AppWork.Customer.CustomerUnit.Added"))); } else { //activity log _customerActivityService.InsertActivity("AddNewCustomerUnit", string.Format(_localizationService.GetResource("ActivityLog.AddNewCustomerUnit"), item.Id), item); return(this.JsonErrorMessage(_localizationService.GetResource("AppWork.Customer.CustomerUnit.NotAdded"))); } }
public async Task <ActionResult> Create(CustomerUnitModel model) { if (ModelState.IsValid) { if (!IsUniqueName(model.Name)) { ModelState.AddModelError(nameof(model.Name), $"Namnet används redan för en annan enhet för denna myndighet"); } else if (!_userService.IsUniqueEmail(model.Email)) { ModelState.AddModelError(nameof(model.Email), $"E-postadressen används redan i tjänsten"); } else { int?customerId = User.TryGetCustomerOrganisationId(); var unit = new CustomerUnit(); unit.Create(_clock.SwedenNow, User.GetUserId(), User.TryGetImpersonatorId(), User.GetCustomerOrganisationId(), model.Name, model.Email, model.LocalAdministrator); await _userService.LogCustomerUnitUserUpdateAsync(model.LocalAdministrator, User.GetUserId(), User.TryGetImpersonatorId()); await _dbContext.AddAsync(unit); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(View), new { id = unit.CustomerUnitId })); } } return(View(model)); }
public CustomerUnitSearchModel PrepareCustomerSearchListModel(CustomerUnitSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } var param = _unitService.GetAllCustomerByUnitId(searchModel.UnitId).Select(c => c.Id).ToArray(); //get items var items = _customerService.GetSearchAllCustomer(Keyword: searchModel.srKeywordCustomer, ExcludeCustomerIds: param); //prepare list model CustomerUnitSearchModel model = new CustomerUnitSearchModel(); model.ListCustomer = items.Select(c => { var m = new CustomerUnitModel(); m.CustomerId = c.Id; m.Username = c.Username; m.FullName = _customerService.GetCustomerFullName(c); m.Email = c.Email; return(m); }).ToList(); return(model); }
public CustomerUnitListModel PrepareCustomerUnitListModel(CustomerUnitSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get items var items = _unitService.GetAllCustomerByUnitId(searchModel.UnitId); //prepare list model var model = new CustomerUnitListModel { //fill in model values from the entity Data = items.Select(c => { var m = new CustomerUnitModel(); m.CustomerId = c.Id; m.Username = c.Username; m.FullName = _customerService.GetCustomerFullName(c); return(m); }).ToList(), Total = items.Count }; return(model); }
public async Task <IActionResult> Edit(CustomerUnitModel model) { if (ModelState.IsValid) { if (!IsUniqueName(model.Name, model.CustomerUnitId)) { ModelState.AddModelError(nameof(model.Name), $"Namnet används redan för en annan enhet för denna myndighet"); } else if (!_userService.IsUniqueEmail(model.Email, customerUnitId: model.CustomerUnitId)) { ModelState.AddModelError(nameof(model.Email), $"E-postadressen används redan i tjänsten"); } else { var unit = _dbContext.CustomerUnits .SingleOrDefault(cu => cu.CustomerUnitId == model.CustomerUnitId); if ((await _authorizationService.AuthorizeAsync(User, unit, Policies.Edit)).Succeeded) { unit.Update(_clock.SwedenNow, User.GetUserId(), User.TryGetImpersonatorId(), model.Name, model.Email, model.IsActive); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(View), new { id = model.CustomerUnitId })); } return(Forbid()); } model.IsCentralAdministrator = User.IsInRole(Roles.CentralAdministrator); } return(View(model)); }
public async Task <ActionResult> Users(int id, string errorMessage = null, string message = null) { var unit = await _dbContext.CustomerUnits.GetCustomerUnitById(id); var users = await GetUnitUsersListItems(id); if ((await _authorizationService.AuthorizeAsync(User, unit, Policies.Edit)).Succeeded) { var model = new CustomerUnitModel { Message = message, ErrorMessage = errorMessage, CustomerUnitId = id, Name = unit.Name, UnitUsers = users, UserPageMode = new UserPageMode { BackController = "Unit", BackAction = nameof(Users), BackId = id.ToSwedishString() } }; return(View(model)); } return(Forbid()); }
public CustomerUnitModel PrepareCustomerUnitModel(CustomerUnitModel model, CustomerUnitMapping item, bool excludeProperties = false) { if (item != null) { //fill in model values from the entity model = model ?? item.ToModel <CustomerUnitModel>(); } return(model); }
public async Task <ActionResult> Edit(int id) { var unit = await GetUnitToHandle(id); if (unit != null) { if ((await _authorizationService.AuthorizeAsync(User, unit, Policies.Edit)).Succeeded) { return(View(CustomerUnitModel.GetModelFromCustomerUnit(unit, User.IsInRole(Roles.CentralAdministrator)))); } } return(Forbid()); }
public async Task <ActionResult> View(int id) { var unit = await GetUnitToHandle(id); if (unit != null) { if ((await _authorizationService.AuthorizeAsync(User, unit, Policies.View)).Succeeded) { return(View(CustomerUnitModel.GetModelFromCustomerUnit(unit))); } } return(Forbid()); }
public CustomerUnitSearchModel PrepareCustomerCheckListModel(CustomerUnitSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get items var items = _unitService.GetAllCustomerByUnitId(searchModel.UnitId); CustomerUnitSearchModel model = new CustomerUnitSearchModel(); //prepare list model model.ListCustomer = items.Select(c => { var m = new CustomerUnitModel(); m.CustomerId = c.Id; m.Username = c.Username; m.FullName = _customerService.GetCustomerFullName(c); m.Email = c.Email; return(m); }).ToList(); return(model); }