public bool Reg(User user) { //1.检查 if (string.IsNullOrEmpty(user.Email) || string.IsNullOrEmpty(user.Password)) { return(false); } //2.记录用户信息 user.RegTime = DateTime.Now; user.Status = true; //2.保存 int cnt = _userRepository.Add(user); return(cnt > 0); }
public async Task <CommandResponse> Handler(CreateUserRequest command) { var user = _mapper.Map <CreateUserRequest, User>(command); if (!user.IsValid()) { _notificationContext.AddNotifications(user.Validation); return(BadRequest(null, Messages.INVALID_FIELDS)); } if (await _userRepository.CheckAlreadyExist(user.Email)) { _notificationContext.AddNotification("Email", Messages.EMAIL_ALREADY_EXISTS); return(BadRequest(null, Messages.INVALID_FIELDS)); } return(Created(await _userRepository.Add(user), Messages.CREATED_SUCCESS)); }
public IActionResult Create([FromBody] UserViewModel user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } User _newUser = new User { Name = user.Name, Profession = user.Profession, Avatar = user.Avatar }; _userRepository.Add(_newUser); _userRepository.Commit(); user = Mapper.Map <User, UserViewModel>(_newUser); CreatedAtRouteResult result = CreatedAtRoute("GetUser", new { controller = "Users", id = user.Id }, user); return(result); }
public async Task <bool> Handle(CreateUserCommand message, CancellationToken cancellationToken) { //添加一个事件到一个 新篮子里面 var userCreatedIntegrationEvent = new UserCreatedIntegrationEvent(message.UserId); //添加然后保存事件 //这里应该就回去找他的事件处理程序 await _userIntegrationEventService.AddAndSaveEventAsync(userCreatedIntegrationEvent); /// 添加 / 更新 用户聚合根 // DDD 模式注释:通过顺序聚合根添加子实体和值对象 // 方法和构造函数,以便验证、不变量和业务逻辑 /// 确保在整个聚合中保持一致性 UserInformation userinfo = null; _logger.LogInformation("----- Creating Order - Order: {@Order}", userinfo); //添加 _userRespository.Add(userinfo); return(await _userRespository.UnitOfWork .SaveEntitiesAsync(cancellationToken)); }
public User Add(User entity) { return(_userRespository.Add(entity)); }
public IResult <User> Add(User entity) { var result = _userRespository.Add(entity); return(new Result <User>(201, result)); }