public void Execute(UserDto request)
        {
            var id = request.Id;

            var user = _context.Users.Find(id);

            if (user == null)
            {
                throw new EntityNotFoundException(id, typeof(UserDto));
            }

            _validator.ValidateAndThrow(request);

            _mapper.Map(request, user);

            _context.SaveChanges();
        }
        public void Execute(EditUserDto request)
        {
            var user = _context.Users.FirstOrDefault(u => !u.IsDeleted && u.Id == request.Id);

            if (user == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(User));
            }

            if (user.Id != _actor.Id && _actor.RoleType != RoleType.Administrator && _actor.RoleType != RoleType.Moderator)
            {
                throw new NotAllowedException(UseCase.getUseCase(this.Id), _actor, $"You can only edit your own profile info.");
            }

            _validator.ValidateAndThrow(request);

            _mapper.Map <EditUserDto, User>(request, user);

            _context.SaveChanges(_actor.Id);
        }
Beispiel #3
0
 public void Execute(AddUser request)
 {
     _validator.ValidateAndThrow(request); var userDto = new Domain.User
     {
         IsDeleted   = false,
         FirstName   = request.FirstName,
         LastName    = request.LastName,
         ModifidedAt = DateTime.Now,
         UserName    = request.UserName
     };
     if (Context.Users.Any(u => u.UserName == userDto.UserName))
     {
         throw new EntityAllreadyExists("Id: " + userDto.Id + " Tip: " + typeof(AddUser));
     }
     try
     {
         Context.SaveChanges();
     }
     catch (Exception)
     {
         throw;
     }
 }