Exemple #1
0
        public User AddUser(User user)
        {
            if (user == null) { throw new ArgumentNullException("user"); }
            using (LocanDataContext ctx = this.GetDbContext()) {
                // make sure that the api key is not already in use
                User existingUser = this.GetUniqueUser(u => u.ApiKey == user.ApiKey, false);
                if (existingUser != null) {
                    string message = string.Format("The ApiKey [{0}] is already being used by another user", user.ApiKey);
                    throw new ApiKeyAlreadyInUseException(message);
                }

                user.Id = Guid.NewGuid();
                user = ctx.Users.Add(user);
                ctx.SaveChanges();

                return user;
            }
        }
Exemple #2
0
        public Guid RegisterUser(string apiKey)
        {
            if (string.IsNullOrWhiteSpace(apiKey)) { throw new ArgumentNullException("apiKey"); }

            User newUser = new User {
                ApiKey = apiKey
            };

            // see if the user exists if so get that ID if not create a new one
            LocanDal dal = new LocanDal();

            User existingUser = dal.GetUniqueUser(user => user.ApiKey == apiKey, false);
            if (existingUser == null) {
                existingUser = dal.AddUser(newUser);
            }

            return existingUser.Id;
        }
Exemple #3
0
 public User UpdateUser(User user)
 {
     if (user == null) { throw new ArgumentNullException("user"); }
     using (LocanDataContext ctx = this.GetDbContext()) {
         User existingUser = this.GetUniqueUser(u => u.Id == user.Id, true);
         existingUser.ApiKey = user.ApiKey;
         existingUser.Email = user.Email;
         return existingUser;
     }
 }