Esempio n. 1
0
        static public void AcquirePackage(RequestContext request)
        {
            int userstate = UserHandler.AuthUser(request);

            if (userstate == 1 || userstate == 2)     //eingeloggt
            {
                User user = UserHandler.GetUserDataByToken(request);
                if (user.coins < 5)
                {
                    Output.WriteConsole(Output.InsufficientCoins);
                    return;
                }

                try
                {
                    CardsPacksDatabaseHandler.AcquirePackage(user);
                    user.coins -= 5;
                    UserHandler.UpdateCoins(user);
                    Output.WriteConsole(Output.PackageTransactionSuccess);
                }
                catch (Exception e)
                {
                    Output.WriteConsole(e.Message);
                }

                return;
            }
            Output.WriteConsole(Output.AuthError);
        }
Esempio n. 2
0
        static public void CreatePackage(RequestContext request)
        {
            int userstate = UserHandler.AuthUser(request);

            if (userstate == 2)     //adminrechte benötigt
            {
                int         counter     = 0;
                DummyCard[] cards       = new DummyCard[5];
                string[]    jsonStrings = PrepareJsonStrings(request.Message);
                foreach (string s in jsonStrings)
                {
                    cards[counter] = JsonConvert.DeserializeObject <DummyCard>(jsonStrings[counter]);
                    counter++;
                }

                try
                {
                    CardsPacksDatabaseHandler.InsertPackage(cards);
                    Output.WriteConsole(Output.PackageAddedSuccess);
                }
                catch (Exception e)
                {
                    Output.WriteConsole(e.Message);
                }

                return;
            }

            if (userstate == 1)
            {
                Output.WriteConsole(Output.PermissionsDenied);
                return;
            }
            Output.WriteConsole(Output.AuthError);
        }