Esempio n. 1
0
        private Response AddPackage(AuthDetails user, Dictionary <string, object> payload)
        {
            // Package needs to consists of 5 cards
            if (!(payload["array"] is JArray rawCards) || rawCards.Count != 5)
            {
                return(Response.Status(Status.BadRequest));
            }
            // Get user and check if its an admin account
            var userSchema = db.GetUser(user.Username);

            if (userSchema is null)
            {
                return(Response.Status(Status.BadRequest));
            }
            if (userSchema.Role != Role.Admin)
            {
                return(Response.Status(Status.Forbidden));
            }
            // Parse given cards
            var cards = CardSchema.ParseRequest(rawCards);

            // Check if all cards were correctly parsed
            if (cards.Count != 5)
            {
                return(Response.Status(Status.BadRequest));
            }
            // Add package and return corresponding response
            var result = db.AddPackage(cards);

            return(Response.Status(result ? Status.Created : Status.Conflict));
        }
Esempio n. 2
0
 public Trade(StoreSchema store, CardSchema card)
 {
     Store = store;
     Card  = card;
 }