/// <summary>
        /// get keymodel bij Key and Email
        /// </summary>
        /// <param name="key"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public KeyModel GetKey(string key, string email)
        {
            var collection = ConfigDB.GetDatabase().GetCollection <KeyModel>("ResetKey");
            var builder    = Builders <KeyModel> .Filter;
            var filter     = builder.Eq(x => x.Key, key) & builder.Eq(x => x.Email, email);

            return(collection.Find(filter).FirstOrDefault());
        }
Exemple #2
0
        /// <summary>
        /// Get all locations that exist in the DB
        /// </summary>
        /// <returns></returns>
        public List <LocationModel> GetAllLocations()
        {
            //Select collection
            var collection = ConfigDB.GetDatabase().GetCollection <LocationModel>("Location");
            List <LocationModel> Locations = collection.Find(Builders <LocationModel> .Filter.Empty).ToList();

            return(Locations);
        }
        /// <summary>
        /// Get user by Username
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public UserModel GetUser(string username)
        {
            //Select collection
            var collection = ConfigDB.GetDatabase().GetCollection <UserModel>("Users");
            //Count documents (select)
            var filter = Builders <UserModel> .Filter.Eq(x => x.Username, username);

            var select = Builders <UserModel> .Projection.Include(x => x.Password);

            UserModel user = collection.Find(filter).FirstOrDefault();

            return(user);
        }
        /// <summary>
        /// Count the open incidents
        /// </summary>
        /// <returns></returns>
        public int CountOpenIncidents(int userId, bool adminRights)
        {
            //Select collection
            var collection = ConfigDB.GetDatabase().GetCollection <IncidentModel>("Incidents");
            //Count documents (select)
            var    filter1 = Builder.Eq(x => x.Status, "open");
            var    filter2 = Builder.Eq(x => x.Status, "open") & Builder.Eq(x => x.UserId, userId);
            double count;

            if (adminRights)
            {
                count = collection.CountDocuments(filter1);
            }
            else
            {
                count = collection.CountDocuments(filter2);
            }
            return(Convert.ToInt32(count));
        }