/// <summary>
        /// Creates a location remark for the respective user
        /// </summary>
        /// <param name="userId">Unique user identification number</param>
        /// <param name="model">CreateLocationModel</param>
        /// <returns>Number of rows affected</returns>
        public async Task <int> Execute(int userId, CreateLocationModel model)
        {
            //TODO: Handle exception
            var entity = new Location
            {
                Label     = model.Label,
                Latitude  = model.Latitude,
                Longitude = model.Longitude,
                Remark    = model.Remark,
                UserId    = userId
            };

            _landmarkRemarkContext.Locations.Add(entity);

            return(await _landmarkRemarkContext.SaveChangesAsync());
        }
        /// <summary>
        /// Create a user
        /// </summary>
        /// <param name="model">Create user model</param>
        /// <returns>Number of rows affected</returns>
        public async Task <int> Execute(CreateUserModel model)
        {
            //TODO: Handle exception
            var entity = new User
            {
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                UserName     = model.UserName,
                Password     = model.Password,
                Email        = model.Email,
                IsActive     = model.IsActive,
                CreationDate = model.CreationDate
            };

            _landmarkRemarkContext.Users.Add(entity);

            return(await _landmarkRemarkContext.SaveChangesAsync());
        }
Exemple #3
0
        public async Task <int> Handle(CreateUserCommand request, CancellationToken cancellationToken)
        {
            var validator = new CreateUserCommandValidator((username) => !_context.Users.Any(x => x.UserName == username));

            validator.ValidateAndThrowUnProcessableEntityException(request);

            var user = new User
            {
                FirstName = request.FirstName.Trim(), //depending on how often we need to do this, we can also write a custom convertor that can trim string but need to think more about what content type we are going to support
                LastName  = request.LastName.Trim(),
                UserName  = request.Username.Trim(),
                CreatedOn = _timeProvider.Now()
            };

            (byte[] passwordHash, byte[] passwordSalt) = CreatePasswordHash(request.Password);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            _context.Users.Add(user);
            await _context.SaveChangesAsync(cancellationToken);

            return(user.Id);
        }
        public async Task AddAsync(T entity)
        {
            await _context.Set <BaseEntity>().AddAsync(entity);

            await _context.SaveChangesAsync();
        }