public CheckIn Add(CheckIn newCheckIn)
        {
            if (_list.Count > 0)
                newCheckIn.Id = _list[_list.Count-1].Id + 1;
            else
                newCheckIn.Id = 1;

            _list.Add (newCheckIn);
            return newCheckIn;
        }
        public void CheckInUserAtPlace(string username, Place place)
        {
            SetupAndCall((dbCmd) =>
            {
                SqlExpressionVisitor<Place> evPlace = OrmLiteConfig.DialectProvider.ExpressionVisitor<Place>();
                SqlExpressionVisitor<User> evUser = OrmLiteConfig.DialectProvider.ExpressionVisitor<User>();
                SqlExpressionVisitor<CheckIn> evCheckIn = OrmLiteConfig.DialectProvider.ExpressionVisitor<CheckIn>();

                // Find the user Id
                int userId;
                evUser.Where(u => u.UserName == username).Select(u => u.Id);
                var userResult = dbCmd.Select(evUser);

                if (userResult.Count == 0)
                    throw new ArgumentException(string.Format("username : '******' does not exist", username));
                userId = userResult[0].Id;

                //// Get the last checkin for the user
                evCheckIn.Where(c => c.UserId == userId).OrderByDescending(c => c.Time).Limit(1);
                var lastCheckIn = dbCmd.Select(evCheckIn);

                if (lastCheckIn.Count != 0)
                {
                    DateTime refTime = DateTime.UtcNow - new TimeSpan
                    (0, SystemConstants.RecentThresholdHours, 0, 0, 0);

                    // If it has been a while allow the checkin
                    if (refTime < lastCheckIn.First().Time)
                    {
                        //// Find the palce for that place id
                        evPlace.Where(p => p.Id == lastCheckIn.First().PlaceId).Limit(1);
                        var existingPlaceResult = dbCmd.Select(evPlace);

                        // if it is the same place just update the time
                        if (existingPlaceResult.First().Name == place.Name &&
                            existingPlaceResult.First().Address == place.Address)
                        {
                            evCheckIn.Where(c => c.Id == lastCheckIn.First().Id).Update(c => c.Time);
                            dbCmd.UpdateOnly(new CheckIn { Time = DateTime.UtcNow }, evCheckIn);
                            return;
                        }
                    }
                }

                // Add place to table if it does not exist
                // compared my name and address
                int placeId;
                evPlace = OrmLiteConfig.DialectProvider.ExpressionVisitor<Place>();
                evPlace.Where(p => p.Name == place.Name && p.Address == place.Address)
                    .Select(p => p.Id);

                var placeResult = dbCmd.Select(evPlace);

                if (placeResult.Count == 0)
                {
                    dbCmd.Insert(place);
                    placeId = (int)dbCmd.GetLastInsertId();
                }
                else
                    placeId = placeResult[0].Id;

                // Check in the user
                CheckIn checkIn = new CheckIn { UserId = userId, PlaceId = placeId, Time = DateTime.UtcNow };
                dbCmd.Insert(checkIn);
            });
        }
 public void Delete(CheckIn checkInToDelete)
 {
     _list.Remove (_list.Find (e=> e.Id == checkInToDelete.Id));
 }