public async Task <AddGenderCommandResponse> Handle(AddGenderCommandRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <AddGenderCommandResponse> next) { if (request.Name is null) { throw new AppException(ResultCode.BadRequest, "name is not exist"); } var existGender = await _genderRepository.GetByName(request.Name); if (existGender is not null) { throw new AppException(ResultCode.BadRequest, "gender is exist"); } _genderRepository.Add(new Gender(request.Name)); return(new AddGenderCommandResponse(true, ResultCode.Success)); }
public async Task <EditGenderCommandResponse> Handle(EditGenderCommandRequest request, CancellationToken cancellationToken, RequestHandlerDelegate <EditGenderCommandResponse> next) { var genderExist = await _genderRepository.GetByName(request.Name); if (genderExist is not null) { throw new AppException(ResultCode.BadRequest, "gender is duplicate"); } var gender = await _genderRepository.GetById(request.Id); if (gender is null) { throw new AppException(ResultCode.BadRequest, "gender is not exist"); } gender.Update(request.Name); _genderRepository.Update(gender); return(new EditGenderCommandResponse(true, ResultCode.Success)); }