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 OfferId = Request.QueryString["offer_id"] != null?Convert.ToInt64(Request.QueryString["offer_id"]) : 0; 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; MainOffer mainOffer = IsService ? SupplierController.GetServiceOfferById(OfferId, SupplierId) : SupplierController.GetBidOfferById(bidId, SupplierId); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName(@"bid_id"); jsonWriter.WriteValue(mainOffer.BidId); jsonWriter.WritePropertyName(@"end_time"); jsonWriter.WriteValue(mainOffer.EndBid); jsonWriter.WritePropertyName(@"city"); jsonWriter.WriteValue(mainOffer.City); jsonWriter.WritePropertyName(@"service_id"); jsonWriter.WriteValue(mainOffer.ServiceId); jsonWriter.WritePropertyName(@"products"); jsonWriter.WriteStartArray(); if (mainOffer.LstProduct != null && mainOffer.LstProduct.Count > 0) { foreach (BidProductUI item in mainOffer.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); jsonWriter.WriteEndObject(); } } jsonWriter.WriteEndArray(); jsonWriter.WritePropertyName(@"total_price"); jsonWriter.WriteValue(mainOffer.TotalPrice); jsonWriter.WritePropertyName(@"num_of_payments"); jsonWriter.WriteValue(mainOffer.NumOfPayments); jsonWriter.WritePropertyName(@"gift"); jsonWriter.WriteValue(mainOffer.Gift); jsonWriter.WritePropertyName(@"supplier_remarks"); jsonWriter.WriteValue(mainOffer.SupplierRemarks); jsonWriter.WritePropertyName(@"customer_comment"); jsonWriter.WriteValue(mainOffer.CustomerComment); jsonWriter.WritePropertyName(@"service_name"); jsonWriter.WriteValue(mainOffer.ServiceName); jsonWriter.WriteEndObject(); } } } } catch (Exception) { } }
public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams) { Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetMaxAge(TimeSpan.Zero); JObject inputData = null; try { using (StreamReader reader = new StreamReader(Request.InputStream)) { using (JsonTextReader jsonReader = new JsonTextReader(reader)) { inputData = JObject.Load(jsonReader); } } } catch { RespondBadRequest(Response); } Int64 supplierId; if (IsAuthorizedRequestSupplier(Request, Response, true, out supplierId)) { Response.ContentType = @"application/json"; try { JToken jt; Int64 bidId = 0; bool isApproved = false; if (inputData.TryGetValue(@"bid_id", out jt)) { bidId = jt.Value <Int64>(); } if (inputData.TryGetValue(@"is_approved", out jt)) { isApproved = jt.Value <bool>(); } var supplier = AppSupplier.FetchByID(supplierId); var bid = Bid.FetchByID(bidId); if (bid.IsActive == false) { RespondError(Response, HttpStatusCode.NotAcceptable, @"inactive-bid"); } long orderId = 0; string response = ""; if (isApproved) { var order = Order.FetchByBidId(bidId); var offerUi = SupplierController.GetBidOfferById(bidId, supplierId); if (offerUi == null || offerUi.BidId <= 0) { RespondError(Response, HttpStatusCode.NotAcceptable, @"inactive-bid"); } decimal TotalPrice = offerUi.TotalPrice; var discount = BidController.GetDiscountForUser(TotalPrice, bid.AppUserId.Value); decimal PriceAfterDiscount = Convert.ToDecimal(discount["PriceAfterDiscount"]); decimal PrecentDiscount = Convert.ToDecimal(discount["PrecentDiscount"]); Int64? CampaignId = Convert.ToInt64(discount["CampaignId"]); var paymentDetails = new PaymentDetails { Amount = (float)PriceAfterDiscount * 100, CreditId = order.Transaction, Exp = order.ExpiryDate, AuthNumber = order.AuthNumber, NumOfPayments = order.NumOfPayments, SupplierToken = supplier.MastercardCode }; try { response = CreditGuardManager.CreateMPITransaction(paymentDetails); } catch (Exception ex) { Helpers.LogProcessing("SupplierBidApprovalHandler - ex -", "\n exception: " + ex.ToString(), true); endRequest(Response, order.AppUserId, bidId); } if (response != "000") { endRequest(Response, order.AppUserId, bidId); } order.IsSendRecived = false; if (CampaignId != 0) { order.CampaignId = CampaignId; } order.TotalPrice = TotalPrice; order.PriceAfterDiscount = PriceAfterDiscount; order.PrecentDiscount = PrecentDiscount; order.CreateDate = DateTime.UtcNow; // order.SpecialInstructions = special_instructions; order.BidId = bidId; order.AppUserId = bid.AppUserId.Value; order.UserPaySupplierStatus = UserPaymentStatus.Payed; order.SupplierId = supplierId; order.Save(); bid.IsActive = false; bid.Save(); var message = BIdMessageController.GetMessageByBidAndSupplier(bidId, supplierId); message.IsActive = false; message.Save(); orderId = order.OrderId; //Notification.SendNotificationAppUserSupplierApproved(Snoopi.web.Localization.PushStrings.GetText("SupplierApproved"), bid.AppUserId.Value, order.OrderId); } else { var message = BIdMessageController.GetMessageByBidAndSupplier(bidId, supplierId); message.ExpirationTime = DateTime.Now.AddHours(-1); message.Save(); } using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream)) { using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter)) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName(@"success"); jsonWriter.WriteValue(true); jsonWriter.WritePropertyName(@"order_id"); jsonWriter.WriteValue(orderId); jsonWriter.WriteEndObject(); } } } catch (Exception ex) { Helpers.LogProcessing("SupplierBidApprovalHandler - ex -", "\n exception: " + ex.ToString(), true); RespondError(Response, HttpStatusCode.NotAcceptable, @"inactive-bid"); } } }