Exemplo n.º 1
0
        public async Task <TResponse <bool> > CanInsert(InsertUserReq user)
        {
            try
            {
                var users = await _readOnlyRepository.QueryAsync <User>(SqlQuery.USER_FIND_BY_NAME,
                                                                        new
                {
                    user.Username
                });

                if (users != null)
                {
                    if (users.IsSuccess)
                    {
                        if (users.Data.Any())
                        {
                            return(await Fail <bool>(ErrorEnum.UserNameHasExist.GetStringValue()));
                        }

                        return(await Ok(true));
                    }

                    return(await Fail <bool>(users.Message));
                }

                return(await Ok(true));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
Exemplo n.º 2
0
        public void OnInsertUserReq(InsertUserReq packet)
        {
            var user      = packet.User;
            var creatorId = packet.CreatorId;

            Sql.Instance.InsertUser(user, creatorId);
        }
Exemplo n.º 3
0
        public async Task <TResponse <bool> > Add(int userId,
                                                  InsertUserReq user)
        {
            try
            {
                var canInsert = await CanInsert(user);

                if (canInsert.IsSuccess)
                {
                    var result = await _writeRepository.ExecuteAsync(SqlQuery.USER_INSERT, new
                    {
                        user.Username,
                        user.Email,
                        user.Name,
                        user.Phone,
                        Password    = Sha512(user.Password),
                        UserCreated = userId,
                        DateCreated = DateTime.Now,
                        UserUpdated = userId,
                        DateUpdated = DateTime.Now
                    });

                    if (result != null)
                    {
                        if (result.IsSuccess)
                        {
                            if (result.Data == 0)
                            {
                                return(await Fail <bool>($"Insert USER {user.Username} is failure"));
                            }

                            return(await Ok(true));
                        }

                        return(await Fail <bool>(result.Message));
                    }

                    return(await Fail <bool>($"Insert USER {user.Username} is failure"));
                }

                return(await Fail <bool>(canInsert.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
Exemplo n.º 4
0
 public async Task <ActionResult <int> > Add(InsertUserReq req)
 {
     return(Ok(await _userService.Add(UserId,
                                      req)));
 }