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

                    DetailedItem i = DataBase.getItemDetails(id);

                    if (i == null)
                    {
                        return(null);
                    }

                    writer.WriteNumber("id", i.id);
                    writer.WriteString("name", i.name);
                    writer.WriteNumber("start_price", i.bidStart);
                    writer.WriteNumber("min_bid", i.current + i.bidIncrement);
                    writer.WriteNumber("current_price", i.current);
                    writer.WriteBoolean("quick_buy", i.buyWithoutBid);
                    if (i.buyWithoutBid)
                    {
                        writer.WriteNumber("buy_price", i.price);
                    }
                    writer.WriteBoolean("new", i.isItNew);
                    writer.WriteString("category", i.category);
                    writer.WriteString("image", i.image);
                    writer.WriteString("description", i.description);
                    writer.WriteString("end_date", i.endDate);
                    writer.WriteString("seller", i.seller);
                    writer.WriteString("sold_to", i.soldTo);

                    writer.WriteEndObject();
                }

                return(stream.ToArray());
            }
        }