public ResultDto DeleteMyComment(Guid id) { Comment comment = _commentAuditBaseRepository.Select.Where(r => r.Id == id).First(); if (comment.CreateUserId != _currentUser.Id) { return(ResultDto.Error("无权限删除他人的评论")); } _commentService.Delete(comment); return(ResultDto.Success()); }
public int LoginValidate(LoginDto input) { var user = _dbContext.SysUsers .Where(u => u.login_name == input.username && u.Pwd == input.password) .FirstOrDefault(); if (user == null) { throw new ResultException(ResultDto.Error("登录用户或登录密码错误")); } _loginLogService.Create(); return(user.Id); }
public void ModifyPwd(ModifyPwdDto input) { if (input.newPassword != input.newPassword2) { throw new ResultException(ResultDto.Error("两次新密码输入不一致!")); } var user = _dbContext.SysUsers.First(u => u.Id == _authContext.UserId); if (user.Pwd != input.oldPassword) { throw new ResultException(ResultDto.Error("原密码错误")); } user.Pwd = input.newPassword; _dbContext.SaveChanges(); }
/// <summary> /// 获取用户信息(包括用户菜单) /// </summary> /// <param name="userId"></param> /// <returns></returns> public UserInfoDto GetUserInfo() { int userId = _authContext.UserId; var dto = new UserInfoDto(); dto.userid = _authContext.UserId; var user = _dbContext.SysUsers.Where(u => u.Id == userId).Select(u => new { u.Name, u.role_ids }).First(); if (user == null) { throw new ResultException(ResultDto.Error("登录超时", 40001)); } dto.username = user.Name; dto.menuList = _menuService.GetMiniList(new SysMenuQueryDto { user_id = userId }); return(dto); }
public async Task Invoke(HttpContext context) { var ex = context.Features.Get <IExceptionHandlerFeature>()?.Error; if (ex == null) { return; } using (var writer = new StreamWriter(context.Response.Body)) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.ContentType = "application/json"; var message = !string.IsNullOrEmpty(ex.Message) ? ex.Message : "Erro interno de sistema."; _serializer.Serialize(writer, ResultDto <bool> .Error(message)); await writer.FlushAsync().ConfigureAwait(false); } }
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement) { var filterContext = context.Resource as Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext; if (!context.User.Identity.IsAuthenticated) { filterContext.Result = new JsonResult(ResultDto.Error("检测不到登录信息!", 40001)); } else { var menuService = filterContext.HttpContext.RequestServices.GetRequiredService <SysMenuService>(); if (!menuService.HasPermission(filterContext.HttpContext.Request.Path)) { filterContext.Result = new JsonResult(ResultDto.Error("没有权限访问!")); } } context.Succeed(requirement); return(Task.CompletedTask); }
public int ImportExcel(Stream stream) { string[] keys = new string[] { "company_name", "model", "type_name", "diy_no", "inbound_date", "amount", "supplier_name", "source", "price", "sn", "remarks" }; var excelList = ExcelHelper.ToList(stream, 3, keys); int successCount = 0; using (var transaction = dbContext.Database.BeginTransaction()) { try { foreach (var item in excelList) { string companyName = item["company_name"].ToString(); int companyId = dbContext.SysCompanys .Where(e => e.Name == companyName) .Select(e => e.Id) .FirstOrDefault(); if (companyId == 0) { throw new ResultException( ResultDto.Error( "第" + (excelList.IndexOf(item) + 3) + "行数据资产所属公司名称在系统不存在!")); } string typeName = item["type_name"].ToString(); int typeId = dbContext.ItAssetTypes.Where(e => e.name == typeName) .Select(e => e.Id) .FirstOrDefault(); if (typeId == 0) { throw new ResultException( ResultDto.Error( "第" + (excelList.IndexOf(item) + 3) + "行数据资产类型名称在系统不存在!")); } string supplierName = item["supplier_name"].ToString(); int? supplierId = dbContext.ItSuppliers.Where(e => e.name == supplierName) .Select(e => e.Id) .FirstOrDefault(); if (supplierId == 0) { supplierId = null; } ItAssetSaveDto dto = new ItAssetSaveDto() { company_id = companyId, type_id = typeId, supplier_id = supplierId, amount = Convert.ToInt32(item["amount"]), attach_guid = Guid.NewGuid().ToString(), diy_no = item["diy_no"].ToString(), inbound_date = Convert.ToDateTime(item["inbound_date"]), model = item["model"].ToString(), price = Convert.ToDecimal(item["price"]), remarks = item["remarks"].ToString(), sn = item["sn"].ToString(), source = item["source"].ToString() }; Create(dto); successCount++; } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } return(successCount); }