public async Task RemoveFromRole(int userId, string role) { var employee = (await _employeeService.GetEmployeeDtoAsync(EmployeeQuery.WithUserId(userId))).Value; switch (role) { case Client: throw new NotSupportedException(); case Employee: if (employee != null) { await _employeeService.DeleteModelAsync(employee.Id); } break; default: if (employee != null && RolesToRights.ContainsKey(role) && employee.Rights.HasFlag(RolesToRights[role])) { employee.Rights = employee.Rights ^ RolesToRights[role]; await _employeeService.UpdateModelAsync(employee); } break; } }
private EmployeeViewModel GetEmployee() { var userId = int.Parse(User.Identity.GetUserId()); var res = _employeeService.GetEmployee(EmployeeQuery.WithUserId(userId)); return(res.Value); }
public async Task <CommandResult> AddOrUpdateEmployeeAsync(EmployeeViewModel employee) { var employeeRes = await GetEmployeeDtoAsync(EmployeeQuery.WithUserId(employee.User.Id)); if (employeeRes.IsFailed) { return(new CommandResult(null, false).From(employeeRes)); } return(await(employeeRes.Value == null ? CreateModelAsync(employee) : UpdateModelAsync(employee))); }
public CommandResult AddOrUpdateEmployee(EmployeeViewModel employee) { var employeeRes = GetEmployeeDto(EmployeeQuery.WithUserId(employee.User.Id)); if (employeeRes.IsFailed) { return(new CommandResult(null, false).From(employeeRes)); } return(employeeRes.Value == null?CreateModel(employee) : UpdateModel(employee)); }
public ActionResult CashierPaymentApprove(AddPaymentCommand command) { if (command == null) { return(RedirectToAction("CashierGetCreditAccounts")); } command.EmployeeId = _employeeService.GetEmployee(EmployeeQuery.WithUserId(int.Parse(User.Identity.GetUserId()))).Value.Id; _employeeService.AddPayment(command); var account = _creditAccountService.GetActualAccountStateDto(new ActualCreditAccountStateQuery() { Id = command.CreditAccountId }); return(RedirectToAction("CashierGetCreditAccounts", "Employee", new { agreementNumber = account.Value.CreditAccount.CreditAgreementNumber })); }
public async Task AddToRole(int userId, string role) { var user = (await _userService.GetUserDtoAsync(UserQuery.WithId(userId))).Value; if (user == null) { return; } var employee = (await _employeeService.GetEmployeeDtoAsync(EmployeeQuery.WithUserId(userId))).Value; switch (role) { case Client: throw new NotSupportedException(); case Employee: if (employee == null) { employee = new EmployeeDto { Rights = EmployeeRights.None, User = user }; await _employeeService.CreateModelAsync(employee); } break; default: if (RolesToRights.ContainsKey(role)) { if (employee == null) { employee = new EmployeeDto { Rights = EmployeeRights.None, User = user }; employee.Rights = employee.Rights | RolesToRights[role]; await _employeeService.CreateModelAsync(employee); } else { employee.Rights = employee.Rights | RolesToRights[role]; await _employeeService.UpdateModelAsync(employee); } } break; } }
public async Task <bool> IsInRole(int userId, string role) { var client = (await _clientService.GetClientDtoAsync(ClientQuery.WithUserId(userId))).Value; var employee = (await _employeeService.GetEmployeeDtoAsync(EmployeeQuery.WithUserId(userId))).Value; switch (role) { case Client: return(client != null); case Employee: return(employee != null); default: return(employee != null && RolesToRights.ContainsKey(role) && employee.Rights.HasFlag(RolesToRights[role])); } }
public async Task <IList <string> > GetRoles(int userId) { var client = (await _clientService.GetClientDtoAsync(ClientQuery.WithUserId(userId))).Value; var employee = (await _employeeService.GetEmployeeDtoAsync(EmployeeQuery.WithUserId(userId))).Value; var res = new List <string>(); if (client != null) { res.Add(Client); } if (employee != null) { res.Add(Employee); foreach (var key in RightsToRoles.Keys) { if (employee.Rights.HasFlag(key)) { res.Add(RightsToRoles[key]); } } } return(res); }