Example #1
0
        public async Task <UserDto> FindByGoogleId(string googleId)
        {
            var user = await _context.Users
                       .FirstOrDefaultAsync(x => x.GoogleId == googleId);

            return(UserTranslator.ToModel(user));
        }
Example #2
0
        /// <summary>
        /// Get single user
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <UserDto> Get(int id)
        {
            var dbUser = await _context.Users.Include(u => u.Office)
                         .FirstOrDefaultAsync(x => x.Id == id);

            var user = UserTranslator.ToModel(dbUser);

            return(user);
        }
Example #3
0
        public async Task <UserDto> CreateFromGoogle(string googleId, UserDto user)
        {
            var dbUser = new User
            {
                GoogleId = googleId,
                Email    = user.Email,
                Name     = user.Name
            };

            _context.Users.Add(dbUser);

            await _context.SaveChangesAsync();

            return(UserTranslator.ToModel(dbUser));
        }
Example #4
0
        public async Task <UserDto> Create(UserDto user, string password)
        {
            var dbUser = new User
            {
                Email    = user.Email,
                Name     = user.Name,
                Password = _passwordHasher.HashPassword(password)
            };

            _context.Users.Add(dbUser);

            await _context.SaveChangesAsync();

            return(UserTranslator.ToModel(dbUser));
        }