public async Task <Messages> AddByUserIdsAsync(int roleId, List <int> userIds, UserClaimModel userClaim) { if (roleId > 0 && userIds != null && userIds.Count > 0) { using (DataTable dt = new DataTable()) { dt.Columns.Add("roleid", typeof(int)); dt.Columns.Add("userid", typeof(int)); foreach (int userid in userIds) { DataRow dr = dt.NewRow(); dr[0] = roleId; dr[1] = userid; dt.Rows.Add(dr); } bool result = await roleUserRepository.AddByDataTableAsync(dt); messages.Msg = result ? "添加成功!!" : "添加失败!!"; messages.Success = result; await logService.AddLogAsync(OperatorLogEnum.Create, string.Format("批量增加角色编号为:{0}的用户编号为{1}{2}", roleId, string.Join(",", userIds), messages.Msg), userClaim.UserId, userClaim.UserName); } } return(messages); }
public async Task AddOrderAsync(Guid cacheId, int number, string clientCountry, string clientIdentificationNumber, string brokerCountry, string brokerIdentificationNumber, string owner1Name, string role) { if (!(role == Roles.User || role == Roles.Admin)) { throw new UnauthorizedAccessException(); } var order = new Order(number, clientCountry, clientIdentificationNumber, brokerCountry, brokerIdentificationNumber, owner1Name, new DateTime()); await _orderRepository.AddAsync(order); await _logService.AddLogAsync($"Dodano nowe zlecenie.", order, owner1Name); _cache.Set(cacheId, order.Id, TimeSpan.FromSeconds(5)); }
public async Task <IHttpActionResult> LogAsync(LogCreateModel logCreateModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } LogCreateDto logCreateDto = logCreateModel.ToLogCreateDto(); try { int id = await _logService.AddLogAsync(logCreateDto, User.Identity.Name); return(Ok(new LogCreationResultModel() { success = id > 0 })); } catch (Exception) { return(Ok(new LogCreationResultModel() { success = false })); } }
public async Task DeleteFileAsync(Guid id, string fileType, string role, string username) { var order = await _orderRepository.GetOrFailAsync(id); await _handler .Validate(async() => { await _orderService.ValidatePermissionsToOrder(username, role, order.Id); await _permissionService.Validate(fileType, role); }) .Run(async() => { var file = order.Files.SingleOrDefault(x => x.FileType == fileType); await _realFileRepository.RemoveAsync(file.Path); await _logService.AddLogAsync($"Usunięto plik: {Path.GetFileName(file.Path)}", order, username); order.UnlinkFile(file.FileType); await _orderRepository.UpdateAsync(order); }) .OnCustomError(x => throw new ServiceException(x.Code), true) .ExecuteAsync(); }
public async Task <Messages> BatchSaveAsync(int roleId, IList <string> codes, UserClaimModel userClaim) { if (roleId > 0 && codes != null && codes.Count > 0) { using (DataTable dt = new DataTable()) { dt.Columns.Add("r_id", typeof(int)); dt.Columns.Add("mpc_code", typeof(string)); foreach (string code in codes) { DataRow dr = dt.NewRow(); dr[0] = roleId; dr[1] = code; dt.Rows.Add(dr); } bool result = rmpcRepository.BatchSave(dt, roleId); messages.Msg = result ? "更新角色权限成功!" : "更新角色权限失败"; messages.Success = result; await logService.AddLogAsync(OperatorLogEnum.Update, string.Format("更新角色编号为:{0}权限,{1}", roleId, messages.Msg), userClaim.UserId, userClaim.UserName); } } return(messages); }
/// <summary> /// 登录 /// </summary> /// <param name="userName">用户名</param> /// <param name="userPwd">密码</param> /// <returns>Task<(bool Succeeded, string Msg)></returns> public async Task <(bool Succeeded, string Msg, int UserId)> Login(string userName, string userPwd) { bool succeeded = false; string msg = string.Empty; int userId = 0; UserEntity user = this.GetModelByUserName(userName); if (user != null && user.U_ID > 0) { userId = user.U_ID; int errorTimes = 0; string pwd1 = MD5Encrypt.MD5(userPwd + user.U_ENCRYPT); if (user.U_DISABLED == false) { //登录错误次数 int maxLoginFailedTimes = config.MaxLoginFailedTimes; if (maxLoginFailedTimes <= 0) { maxLoginFailedTimes = 5; } if (user.U_ERRORTIMES < maxLoginFailedTimes) { if (user.U_PWD == pwd1) { succeeded = true; msg = "登录系统,成功"; } else { errorTimes = user.U_ERRORTIMES + 1; int sErrorTimes = maxLoginFailedTimes - errorTimes; if (sErrorTimes > 0) { msg = "密码错误,您今天还可尝试" + sErrorTimes + "次"; } else { msg = "您今天登录错误次数过多,今天不可再登录,欢迎明天回来"; } } } else { errorTimes = user.U_ERRORTIMES + 1; msg = "您今天登录错误次数过多,今天不可再登录,欢迎明天回来"; } //更新用户登录信息 await this.UpdateByLoginAsync(user.U_ID, webHelper.GetCurrentIpAddress(), errorTimes); } else { msg = "登录系统,该用户状态为禁止登录"; } } else { msg = "用户名不存在"; } //记录登录日志 await logService.AddLogAsync(OperatorLogEnum.Login, msg, userId, userName); return(succeeded, msg, userId); }