Пример #1
0
        public static byte[] autobidSubscribeResponse(string token, int itemId, int maxPrice)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                using (Utf8JsonWriter writer = new Utf8JsonWriter(stream, JW_OPTS))
                {
                    writer.WriteStartObject();

                    byte b = DataBase.setAutoBid(token, itemId, maxPrice);

                    switch (b)
                    {
                    case 5:
                        throw new Exception("Database error");
                        break;

                    case 4:
                        writer.WriteBoolean("success", false);
                        writer.WriteString("problem", "Item not found!");
                        break;

                    case 3:
                        writer.WriteBoolean("success", false);
                        writer.WriteString("problem", "Bidding has ended!");
                        break;

                    case 2:
                        writer.WriteBoolean("success", false);
                        writer.WriteString("problem", "Autobid limit too high!");
                        break;

                    case 1:
                        writer.WriteBoolean("success", false);
                        writer.WriteString("problem", "Autobid limit too low!");
                        break;

                    case 0:
                        writer.WriteBoolean("success", true);
                        writer.WriteNumber("price", DataBase.priceRefresh(itemId));
                        break;

                    default:
                        writer.WriteBoolean("success", false);
                        writer.WriteString("problem", "Unknown error");
                        break;
                    }

                    writer.WriteEndObject();
                }

                return(stream.ToArray());
            }
        }