public UserResponse Post() { var request = new UserRequest(this); var user = this.Repository.Query<SewebarKey.User>() .FirstOrDefault(u => u.Username == request.UserName && u.Password == request.Password); if (user == null) { user = request.GetUser(); this.Repository.Add(user); } var database = request.GetDatabase(user); if (database != null) { user.Databases.Add(database); } this.Repository.Save(user); return new UserResponse(user); }
public DatabaseResponse Post(string username) { var request = new UserRequest(this); var user = this.GetSewebarUser(); var database = request.GetDatabase(user); if (user == null) { var owner = request.Owner; if (owner != null) { // user to be registered user = new SewebarKey.User { Username = owner.Username, Password = owner.Password }; this.Repository.Add(user); } else { return ThrowHttpReponseException<DatabaseResponse>( "No user for database.", HttpStatusCode.BadRequest); } } if (database != null) { user.Databases.Add(database); this.Repository.Save(database); return new DatabaseResponse(database); } return ThrowHttpReponseException<DatabaseResponse>( "No database to register", HttpStatusCode.BadRequest); }