public async Task <Unit> Handle(DeleteComplaintCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Complaints.FindAsync(request.Id);

            if (entity == null || entity.UserId != _user.Id)
            {
                throw new NotFoundException();
            }

            _context.Complaints.Remove(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemplo n.º 2
0
        public async Task <Unit> Handle(RegisterCommand request, CancellationToken cancellationToken)
        {
            var entity = new User
            {
                Name     = request.Name,
                Email    = request.Email,
                Password = request.Password,
                IsActive = true,
            };

            _context.Users.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <int> Handle(CreateComplaintCommand request, CancellationToken cancellationToken)
        {
            var entity = new Complaint
            {
                Title       = request.Title,
                Description = request.Description,
                Date        = DateTime.UtcNow,
                UserId      = _user.Id
            };

            _context.Complaints.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
Exemplo n.º 4
0
        public async Task <Unit> Handle(UpdateComplaintCommand request, CancellationToken cancellationToken)
        {
            var entity = await _context.Complaints.FindAsync(request.Id);

            if (entity == null || entity.UserId != _user.Id)
            {
                throw new NotFoundException();
            }

            entity.Title         = request.Title;
            entity.Description   = request.Description;
            entity.LastUpdatedOn = DateTime.UtcNow;

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }