Ejemplo n.º 1
0
 /// <summary>
 /// constructs a GPSUser object from a generic BsonDocument
 /// </summary>
 /// <param name="usr">BsonDocument</param>
 /// <returns>GPSUser created</returns>
 public static GpsUser GetUserFromDoc(BsonDocument usr, bool includeExtraData)
 {
     GpsUser _user = new GpsUser();
     // set properties
     _user.CreatedDate = usr["CreatedDate"].AsDateTime;
     _user.Key = usr["_id"].AsGuid;
     _user.Name = usr["Name"].AsString;
     if (includeExtraData)
     {
         BsonValue ExtraDataValue;
         usr.TryGetValue(extraData.ToLower(), out ExtraDataValue);
         if (ExtraDataValue != null)
             _user.Data = ExtraDataValue.AsBsonDocument.ToJson();
     }
     return _user;
 }
Ejemplo n.º 2
0
 public GpsUser InsertUser(string name)
 {
     GpsUser _newUser = new GpsUser(){ Name = name};
     return locationService.InsertUser(_newUser);
 }
Ejemplo n.º 3
0
 public virtual void UpdateUser(GpsUser user)
 {
     dataProvider.UpdateUser(user);
 }
Ejemplo n.º 4
0
 public virtual GpsUser InsertUser(GpsUser user)
 {
     return dataProvider.InsertUser(user);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Update the user
 /// </summary>
 /// <param name="user">GPSUser object</param>
 public void UpdateUser(GpsUser user)
 {
     // serialize the user
     BsonDocument doc = user.ToBsonDocument();
     // Add extra data (in case we have)
     Utilities.AddExtraData(doc, user);
     // save user
     DB.GetCollection<BsonDocument>(_userColection).Save<BsonDocument>(doc);
 }
Ejemplo n.º 6
0
        //public IList<GPSUser> GetUsers()
        //{
        //    RegisterGpsUserClass();
        //    List<GPSUser> ret = new List<GPSUser>();
        //    MongoCollection collection = DB.GetCollection<BsonDocument>(_userColection);
        //    foreach (BsonDocument usr in collection.FindAllAs<BsonDocument>())
        //    {
        //        ret.Add(GetUserFromDoc(usr, true));
        //    }
        //    return ret;
        //}
        /// <summary>
        /// Register/insert a new user into database
        /// </summary>
        /// <param name="user">User object</param>
        /// <returns>User object</returns>
        public GpsUser InsertUser(GpsUser user)
        {
            // serialize the user
            BsonDocument doc = user.ToBsonDocument();
            // Add extra data (in case we have)
            Utilities.AddExtraData(doc, user);
            // add into user colection inside database
            DB.GetCollection<BsonDocument>(_userColection).Insert<BsonDocument>(doc);

            return user;
        }