Exemplo n.º 1
0
        public async Task <UserDTO> Handle(PostUserCommand request, CancellationToken cancellationToken)
        {
            var data = new userModel()
            {
                Name     = request.Data.Attributes.Name,
                Username = request.Data.Attributes.Username,
                Email    = request.Data.Attributes.Email,
                Password = request.Data.Attributes.Password,
                Address  = request.Data.Attributes.Address
            };

            _context.Add(data);
            await _context.SaveChangesAsync();

            var user   = _context.userModels.First(x => x.Username == request.Data.Attributes.Username);
            var target = new TargetCommand()
            {
                Id = user.Id, Email_destination = user.Email
            };

            var command = new PostCommand()
            {
                Title   = "hello",
                Message = "this is message body",
                Type    = "email",
                From    = 123456,
                Targets = new List <TargetCommand>()
                {
                    target
                }
            };

            var attributes = new Attribute <PostCommand>()
            {
                Attributes = command
            };

            var httpContent = new CommandDTO <PostCommand>()
            {
                Data = attributes
            };

            var jsonObject = JsonConvert.SerializeObject(httpContent);
            var content    = new StringContent(jsonObject, Encoding.UTF8, "application/json");

            await client.PostAsync("http://localhost:5007/notification", content);

            return(new UserDTO()
            {
                Message = "Successfully Added",
                Success = true
            });
        }
        public async Task <UserDTO> Handle(DeleteUserCommand request, CancellationToken cancellationToken)
        {
            var data = await _context.userModels.FindAsync(request.Id);

            if (data == null)
            {
                return(null);
            }
            else
            {
                _context.userModels.Remove(data);
                await _context.SaveChangesAsync();

                return(new UserDTO {
                    Message = "Successfully deleted Data", Success = true
                });
            }
        }