Esempio n. 1
0
        public void CreateRoute(string routeName, List <string> routePoints, int userId)
        {
            var user  = _context.Users.FirstOrDefault(x => x.Id == userId);
            var route = new Route
            {
                RouteName = routeName,
                Owner     = user
            };

            var routePointsEntity = routePoints.Select(x => new RoutePoint
            {
                PointName = x
            })
                                    .ToList();

            route.RoutePoints = routePointsEntity;
            _context.Routes.Add(route);
            _context.SaveChanges();
        }
Esempio n. 2
0
        public User Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new AppException("Username " + user.Username + " is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }