public bool UpdateParticipantCount(long eventId)
        {
            var count = DatabaseManager.CountResults($"SELECT * FROM Teilnehmer WHERE Veranstaltung={eventId}");

            return(DatabaseManager.ExecutePut("Veranstaltungen", eventId, new Dictionary <string, string> {
                { "Teilnehmerzahl", count.ToString() }
            }));
        }
Example #2
0
        public bool CheckIfCalendarPermissions(long organizerId, long calendarId)
        {
            if (CheckIfAllPermissions(organizerId))
            {
                return(true);
            }

            return(CheckIfAdminPermissions(organizerId) || DatabaseManager.CountResults($"SELECT * FROM Kalenderberechtigte WHERE Kalender={calendarId} AND Veranstalter={organizerId}") == 1);
        }
Example #3
0
        public bool CheckIfAdminPermissions(long organizerId)
        {
            if (CheckIfAllPermissions(organizerId))
            {
                return(true);
            }

            return(DatabaseManager.CountResults($"SELECT * FROM Admins WHERE Id={organizerId}") == 1);
        }
Example #4
0
        public bool CheckIfEventCanBeBooked(long eventId)
        {
            var dt                       = CalendarManager.GetDateTime(DateTime.Now);
            var SelectById               = $"SELECT * FROM Veranstaltungen WHERE Id={eventId}";
            var FilterByTimeLimit        = $"Anmeldefrist>{dt}";
            var FilterByParticipantLimit = $"(Teilnehmerzahl < Teilnehmerlimit OR Teilnehmerlimit < 0)";

            return(DatabaseManager.CountResults($"{SelectById} AND {FilterByTimeLimit} AND {FilterByParticipantLimit}") == 1);
        }
        public string GenerateUniqueCode()
        {
            string result = null;

            do
            {
                result = Guid.NewGuid().ToString();
            }while (DatabaseManager.CountResults($"SELECT * FROM Emailverifizierungen WHERE Code=\"{result}\"") > 0);

            return(result);
        }
Example #6
0
        public long VerifyUser(long id)
        {
            DatabaseManager.ExecutePut("Nutzerdaten", id, new Dictionary <string, string> {
                { "Verifiziert", "1" }
            });

            var user      = DatabaseManager.ExecuteGet("Nutzerdaten", id, GetUserKeyTableDictionary());
            var u         = Json.DeserializeObject(user);
            var email     = Json.GetKvpValue(u, "email", false);
            var vorname   = Json.GetKvpValue(u, "vorname", false);
            var nachname  = Json.GetKvpValue(u, "nachname", false);
            var abteilung = Json.GetKvpValue(u, "abteilung", false);

            var firstId = DatabaseManager.GetId($"SELECT * FROM Nutzerdaten WHERE Email={email} AND Verifiziert=1");

            if (firstId == null)
            {
                return(-1);
            }

            var newId = Convert.ToInt64(firstId);

            if (newId < id)
            {
                var userPost = new UserPost {
                    abteilung = Json.DeserializeString(abteilung), email = Json.DeserializeString(email), vorname = Json.DeserializeString(vorname), nachname = Json.DeserializeString(nachname)
                };
                if (!PutUser(Convert.ToInt64(firstId), userPost))
                {
                    return(-1);
                }

                DatabaseManager.ExecuteNonQuery($"UPDATE Buchungen SET Nutzer={newId} WHERE Nutzer={id}");
            }

            if (DatabaseManager.CountResults("SELECT * FROM Veranstalter WHERE Autorisiert=1") == 0 && DatabaseManager.CountResults($"SELECT * FROM Veranstalter WHERE Id={id}") == 1)
            {
                DatabaseManager.ExecutePut("Veranstalter", id, new Dictionary <string, string> {
                    { "Autorisiert", "1" }
                });
            }

            if (DatabaseManager.CountResults("SELECT * FROM Admins") == 0)
            {
                new AdminsModel().PostAdmin(id);
            }

            return(id);
        }
        public bool PostCalendarOrganizer(long calendarId, CalendarPost calendarPost)
        {
            var organizerId = calendarPost.veranstalter;

            if (DatabaseManager.CountResults($"SELECT * FROM Veranstalter WHERE Id={organizerId} AND Autorisiert=1") != 1)
            {
                return(false);
            }

            if (DatabaseManager.CountResults($"SELECT * FROM Kalenderberechtigte WHERE Veranstalter={organizerId} AND Kalender={calendarId}") == 1)
            {
                return(false);
            }

            DatabaseManager.ExecutePost("Kalenderberechtigte", calendarPost.ToAuthorizationDictionary(calendarId));
            return(true);
        }
        public bool DeleteCalendarOrganizer(long calendarId, long organizerId)
        {
            var c = DatabaseManager.CountResults($"SELECT * FROM Kalenderberechtigte WHERE Kalender={calendarId}");

            if (c <= 1)
            {
                return(false);
            }
            else
            {
                var id = DatabaseManager.GetId($"SELECT * FROM Kalenderberechtigte WHERE Kalender={calendarId} AND Veranstalter={organizerId}");
                if (id == null)
                {
                    return(false);
                }
                else
                {
                    return(DatabaseManager.ExecuteDelete("Kalenderberechtigte", Convert.ToInt64(id)));
                }
            }
        }