Esempio n. 1
0
        public override void Get(HttpRequest Request, HttpResponse Response, params string[] PathParams)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetMaxAge(TimeSpan.Zero);

            try
            {
                Int64 SupplierId;
                if (IsAuthorizedRequestSupplier(Request, Response, true, out SupplierId))
                {
                    Response.ContentType = @"application/json";
                    using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream))
                    {
                        using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter))
                        {
                            Int64 BidId = Request.QueryString["bid_id"] != null?Convert.ToInt64(Request.QueryString["bid_id"]) : 0;

                            bool IsService = Request.QueryString["is_service"] != null?Convert.ToBoolean(Request.QueryString["is_service"]) : false;

                            MainBid mainBid = IsService ? SupplierController.GetNewServiceBidById(BidId, SupplierId) : SupplierController.GetNewBidById(BidId, SupplierId);


                            if (mainBid != null)
                            {
                                jsonWriter.WriteStartObject();
                                jsonWriter.WritePropertyName(@"bid_id");
                                jsonWriter.WriteValue(mainBid.BidId);
                                jsonWriter.WritePropertyName(@"end_time");
                                jsonWriter.WriteValue(mainBid.EndBid);
                                jsonWriter.WritePropertyName(@"city");
                                jsonWriter.WriteValue(mainBid.City);

                                jsonWriter.WritePropertyName(@"products");
                                jsonWriter.WriteStartArray();
                                string  strGift    = "";
                                decimal totalPrice = 0;
                                if (mainBid.LstProduct != null && mainBid.LstProduct.Count > 0)
                                {
                                    foreach (BidProductUI item in mainBid.LstProduct)
                                    {
                                        jsonWriter.WriteStartObject();

                                        jsonWriter.WritePropertyName(@"product_id");
                                        jsonWriter.WriteValue(item.ProductId);
                                        jsonWriter.WritePropertyName(@"product_name");
                                        jsonWriter.WriteValue(item.ProductName);
                                        jsonWriter.WritePropertyName(@"product_amount");
                                        jsonWriter.WriteValue(item.ProductAmount);
                                        jsonWriter.WritePropertyName(@"product_image");
                                        jsonWriter.WriteValue(item.ProductImage);
                                        jsonWriter.WritePropertyName(@"order_amount");
                                        jsonWriter.WriteValue(item.Amount);
                                        jsonWriter.WritePropertyName(@"product_price");
                                        jsonWriter.WriteValue(item.Price * item.Amount);

                                        strGift    += (item.ProductGift != null && item.ProductGift.Trim() != "" ? item.ProductGift + ", " : "");
                                        totalPrice += item.Price * item.Amount;
                                        jsonWriter.WriteEndObject();
                                    }
                                }

                                jsonWriter.WriteEndArray();

                                jsonWriter.WritePropertyName(@"total_price");
                                jsonWriter.WriteValue(totalPrice);

                                int index = strGift.LastIndexOf(",");
                                if (index > 0)
                                {
                                    strGift = strGift.Substring(0, index);
                                }

                                jsonWriter.WritePropertyName(@"gift");
                                jsonWriter.WriteValue(strGift);

                                jsonWriter.WritePropertyName(@"customer_comment");
                                jsonWriter.WriteValue(mainBid.CustomerComment);

                                jsonWriter.WritePropertyName(@"service_name");
                                jsonWriter.WriteValue(mainBid.ServiceName);


                                jsonWriter.WritePropertyName(@"service_id");
                                jsonWriter.WriteValue(mainBid.ServiceId);

                                jsonWriter.WriteEndObject();
                            }
                            else
                            {
                                RespondError(Response, HttpStatusCode.BadRequest, "bid-expiry-date");
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
        }