Commit 5deb0c6d by 李承祥

用户修改密码/account/password;;/sheet/sheetlist接口增加一个条件source。

parent 7173b51f
......@@ -135,5 +135,19 @@ public ApiResponse SetHospital([FromBody]SetHospitalRequest request)
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
/// <summary>
/// 修改用户密码
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("password")]
[HttpPost]
public ApiResponse<UserResponse> Password([FromBody]PasswordRequest request)
{
var userid = _claim.At(request.Token).UserID;
var user = _userService.UpdatePwd(request, userid);
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
}
}
......@@ -35,7 +35,7 @@ public class SheetController : Controller
[HttpPost]
public ApiResponse SheetList([FromBody]SheetRequest request)
{
var sheetList = _sheetSevice.SheetList(request.AllotID);
var sheetList = _sheetSevice.SheetList(request.AllotID, request.Source);
return new ApiResponse(ResponseType.OK, sheetList);
}
......
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Performance.DtoModels
{
public class PasswordRequest : ApiRequest
{
/// <summary>
/// 原始密码
/// </summary>
public string OldPwd { get; set; }
/// <summary>
/// 新设密码
/// </summary>
public string NewPwd { get; set; }
public class PasswordRequestValidator : AbstractValidator<PasswordRequest>
{
public PasswordRequestValidator()
{
RuleFor(x => x.OldPwd).NotNull().NotEmpty();
RuleFor(x => x.NewPwd).NotNull().NotEmpty();
}
}
}
}
......@@ -12,6 +12,8 @@ public class SheetRequest : ApiRequest
{
public int AllotID { get; set; }
public int Source { get; set; }
}
public class SheetRequestValidator : AbstractValidator<SheetRequest>
{
......
......@@ -47,13 +47,16 @@ public class SheetSevice : IAutoInjection
/// </summary>
/// <param name="allotID"></param>
/// <returns></returns>
public List<SheetResponse> SheetList(int allotID)
public List<SheetResponse> SheetList(int allotID, int source)
{
var allot = _perforAllotRepository.GetEntity(t => t.ID == allotID);
if (allot == null)
throw new PerformanceException("参数allotid无效");
int[] arr = new int[] { 1, 2 };
if (!arr.Contains(source))
throw new PerformanceException("参数source无效");
var sheetList = _perforImSheetRepository.GetEntities(t => t.AllotID == allotID);
var sheetList = _perforImSheetRepository.GetEntities(t => t.AllotID == allotID && t.Source == source);
return Mapper.Map<List<SheetResponse>>(sheetList);
}
......
......@@ -200,5 +200,27 @@ public UserResponse UpdateSelf(UserRequest request)
throw new PerformanceException("保存失败");
return Mapper.Map<UserResponse>(user);
}
/// <summary>
/// 修改用户
/// </summary>
/// <param name="request"></param>
/// <param name="userId"></param>
/// <returns></returns>
public UserResponse UpdatePwd(PasswordRequest request, int userId)
{
var user = _userRepository.GetEntity(t => t.ID == userId);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{userId}");
if (request.OldPwd != user.Password)
throw new PerformanceException("原密码错误");
user.Password = string.IsNullOrEmpty(request.NewPwd) ? user.Password : request.NewPwd;
if (!_userRepository.Update(user))
throw new PerformanceException("保存失败");
return Mapper.Map<UserResponse>(user);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment