Пример #1
0
        public async Task <Response> Handle(AddUserRequest request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                AddNotification("Request", Resource.RequestNotbeNull);
                return(new Response(this));
            }

            //Verificar se o usuario existe
            if (_repositoryUser.Exists(x => x.Email == request.Email))
            {
                AddNotification("Email", Resource.EmailExists);
                return(new Response(this));
            }

            Entities.User user = new Entities.User(request.FirstName, request.LastName, request.Email, request.Password);
            AddNotifications(user);

            if (IsInvalid())
            {
                return(new Response(this));
            }
            user = _repositoryUser.Add(user);

            AddUserNotification addUserNotification = new AddUserNotification(user);
            var response = new Response(this, user);

            await _mediator.Publish(addUserNotification);

            return(await Task.FromResult(response));
        }
Пример #2
0
        public AddUserResponse AddUser(AddUserRequest request)
        {
            //TODO mudar mensagem
            if (request == null)
            {
                AddNotification("AddUser", Message.X0_IsRequired.ToFormat("AddUser"));
            }

            var name    = new Name(request.FirstName, request.LastName);
            var email   = new Email(request.Email);
            var newUser = new GTUser(name, email, request.Password);

            AddNotifications(newUser, name, email);

            if (_repositorieUser.Exist(o => o.Email.Adress == request.Email))
            {
                AddNotification(Message.Email, Message.X1_Exist.ToFormat(Message.Email, request.Email));
            }

            if (IsInvalid())
            {
                return(null);
            }

            newUser = _repositorieUser.Add(newUser);

            return((AddUserResponse)newUser);
        }
        public IActionResult Post([FromBody] UserDto model)
        {
            User user = _mapper.Map <User>(model);

            _repo.Add(user);
            if (_repo.SaveChanges())
            {
                return(Created($"/user/{model.Id}", _mapper.Map <UserDto>(user)));
            }

            return(BadRequest("Usuario não cadastrado"));
        }
Пример #4
0
        public async Task <IActionResult> Post(User model)
        {
            try
            {
                _repo.Add(model);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/user/{model.Id}", model));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco Dados Falhou"));
            }

            return(BadRequest());
        }
Пример #5
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = repository.Get(model.Name);
                if (user == null)
                {
                    // добавляем пользователя в бд
                    repository.Add(new User {
                        Name = model.Name, Password = model.Password
                    });
                    await Authenticate(user); // аутентификация

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
Пример #6
0
        public async void AddUser(User user)
        {
            _userRepository.Add(user);

            _serviceBookUser.createProfile(user._id);
        }
Пример #7
0
 public async Task Add(User Object)
 {
     await _users.Add(Object);
 }