//public List<JObject> Post(/*List<JObject> supplierJSONList HttpClient httpContentList*/ IEnumerable<SPARInsightManagement.WebAPI.Code.SupplierNotification> obj) public IEnumerable <SupplierNotification> Post(IEnumerable <SupplierNotification> supplierNotificationList) { List <SupplierNotification> supplierNotificationReturnList = new List <SupplierNotification>(); foreach (SupplierNotification supplierNotification in supplierNotificationList) { SupplierNotification supplierNotificationReturn = Models.SupplierModel.SupplierValidation(supplierNotification); supplierNotificationReturnList.Add(supplierNotificationReturn); } return(supplierNotificationReturnList); }
protected void btnSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } MessageUI MessageUI = new MessageUI(); MessageUI.Description = txtDescription.Text; if (IsNewMode) { List <string> SendTo = new List <string>(); foreach (ListItem item in ddlSendTo.Items) { if (item.Selected) { SendTo.Add(item.Value); } } MessageId = MessagesController.CreateNewMessage(MessageUI); if ((SendTo.Count == 1 && SendTo[0] == "Suppliers") || SendTo.Count == 0 || SendTo.Count == 2) { SupplierNotification.SendNotificationNewMessage(MessageUI.Description); } if ((SendTo.Count == 1 && SendTo[0] == "AppUsers") || SendTo.Count == 0 || SendTo.Count == 2) { // int results = FcmService.SendFcmNotification(MessageUI.Description); // Notification.SendNotificationNewMessageToAllDevices(MessageUI.Description); //var result = FcmService.SendFcmNotification(MessageUI.Description); } } if (IsNewMode) { string successMessage = MessagesStrings.GetText(@"MessageMessageCreated"); string url = @"EditMessage.aspx?ID=" + MessageId.ToString(); url += @"&message-success=" + Server.UrlEncode(successMessage); Response.Redirect(url, true); } else { string successMessage = MessagesStrings.GetText(@"MessageMessageSaved"); string url = @"EditMessage.aspx?message-success=" + Server.UrlEncode(successMessage); url += @"&ID=" + MessageId.ToString(); Response.Redirect(url, true); } }
//public static JObject SupplierValidation(JObject supplierJSON) public static SupplierNotification SupplierValidation(SupplierNotification supplier) { //SupplierNotification supplierNotificationReturn = null; //var supplier = JsonConvert.DeserializeObject<Supplier>(supplierJSON.ToString()); //var deserializedItemsFromItems = JsonConvert.DeserializeObject<List<Item>>(itemsSerialized); if (Directory.Exists(supplier.FolderPath)) { string[] qvwFileList = Directory.GetFiles(supplier.FolderPath, "*.qvw"); if (qvwFileList.Length > 0) { foreach (string qvwFile in qvwFileList) { DateTime qvwDateTime = File.GetLastWriteTime(qvwFile); supplier.File = Path.GetFileName(qvwFile); supplier.FileModifiedDate = qvwDateTime; supplier.FileSize = Convert.ToDecimal(((new System.IO.FileInfo(qvwFile).Length) / 1024) / 1024); switch (supplier.OptionId) { case 1: //Option 1 { int daylimit = Convert.ToInt32(ConfigurationManager.AppSettings["ReleaseOption1DayLimit"]); if ((qvwDateTime - DateTime.Now).TotalDays < daylimit) { supplier.IsValid = false; supplier.Note = String.Format("{0} {1}", "File older than specified limit of", daylimit); } else { supplier.IsValid = true; supplier.Note = String.Format("{0}", "Success"); } break; } case 2: //Option 2 { int daylimit = Convert.ToInt32(ConfigurationManager.AppSettings["ReleaseOption2DayLimit"]); if ((qvwDateTime - DateTime.Now).TotalDays < daylimit) { supplier.IsValid = false; supplier.Note = String.Format("{0} {1}", "File older than specified limit of", daylimit); } else { supplier.IsValid = true; supplier.Note = String.Format("{0}", "Success"); } break; } case 3: //Weekly { int daylimit = Convert.ToInt32(ConfigurationManager.AppSettings["ReleaseOptionWeeklyDayLimit"]); if ((qvwDateTime - DateTime.Now).TotalDays < daylimit) { supplier.IsValid = false; supplier.Note = String.Format("{0} {1}", "File older than specified limit of", daylimit); } else { supplier.IsValid = true; supplier.Note = String.Format("{0}", "Success"); } break; } } } } else { supplier.File = ""; supplier.FileModifiedDate = Convert.ToDateTime("1903/01/01"); supplier.FileSize = 0; supplier.IsValid = false; supplier.Note = String.Format("{0} - {1}", "No .QVW file exist in folder.", supplier.FolderPath); } } else { supplier.File = ""; supplier.FileModifiedDate = Convert.ToDateTime("1903/01/01"); supplier.FileSize = 0; supplier.IsValid = false; supplier.Note = String.Format("{0} - {1}", "Folder path does not exist.", supplier.FolderPath); } //var json = JsonConvert.SerializeObject(supplier); //supplierNotificationReturn = JObject.Parse(JsonConvert.SerializeObject(supplier)); //string supplierNotificationJSON = JsonConvert.SerializeObject(supplierNotificationList, Formatting.Indented); return(supplier); }
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 AppUserId; if (IsAuthorizedRequest(Request, Response, true, out AppUserId)) { Response.ContentType = @"application/json"; try { JToken jt; string response_code = null, card_tk = null, expire_date = null, last4_digits = null, id_number = null, special_instructions = null, response_error_message = null; Int64 bid_id = 0, offer_id = 0, donation_id = 0; Int64 campaign_id = 0; //if (inputData.TryGetValue(@"response_code", out jt)) response_code = jt.Value<string>(); //if (inputData.TryGetValue(@"response_error_message", out jt)) response_error_message = jt.Value<string>(); if (inputData.TryGetValue(@"card_tk", out jt)) { card_tk = jt.Value <string>(); } if (inputData.TryGetValue(@"expire_date", out jt)) { expire_date = jt.Value <string>(); } if (inputData.TryGetValue(@"special_instructions", out jt)) { special_instructions = Regex.Replace(jt.Value <string>(), @"\p{Cs}", ""); } if (inputData.TryGetValue(@"last4_digits", out jt)) { last4_digits = jt.Value <string>(); } if (inputData.TryGetValue(@"id_number", out jt)) { id_number = jt.Value <string>(); } if (inputData.TryGetValue(@"bid_id", out jt)) { bid_id = jt.Value <Int64>(); } if (inputData.TryGetValue(@"offer_id", out jt)) { offer_id = jt.Value <Int64>(); } //if (inputData.TryGetValue(@"donation_id", out jt)) donation_id = jt.Value<Int64>(); if (inputData.TryGetValue(@"campaign_id", out jt) && jt != null) { campaign_id = jt.Value <Int64?>() ?? 0; } using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream)) { using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter)) { if (Order.FetchByBidId(bid_id) != null) { RespondError(Response, HttpStatusCode.BadRequest, @"already-order"); } Order order = new Order(); //if (response_code == OrderController.RESPONSE_CODE_OK) //{ AppUserCard paymentToken = AppUserCard.FetchByAppUserId(AppUserId); if (paymentToken == null) { paymentToken = new AppUserCard(); } paymentToken.AppUserId = AppUserId; paymentToken.CardToken = card_tk; paymentToken.ExpiryDate = expire_date; paymentToken.Last4Digit = last4_digits; if (!String.IsNullOrEmpty(id_number)) { paymentToken.IdNumber = id_number; } paymentToken.Save(); // } Dictionary <string, string> result = BidController.GetDiscount(offer_id, AppUserId); decimal TotalPrice = result["TotalPrice"] != null?Convert.ToDecimal(result["TotalPrice"].ToString()) : 0; decimal PriceAfterDiscount = result["PriceAfterDiscount"] != null?Convert.ToDecimal(result["PriceAfterDiscount"].ToString()) : 0; decimal PrecentDiscount = result["PrecentDiscount"] != null?Convert.ToDecimal(result["PrecentDiscount"].ToString()) : 0; Int64?CampaignId = result["CampaignId"] != null ? (Int64?)Convert.ToInt64(result["CampaignId"].ToString()) : null; if (CampaignId != 0) { order.CampaignId = CampaignId; } order.TotalPrice = TotalPrice; order.PriceAfterDiscount = PriceAfterDiscount; order.PrecentDiscount = PrecentDiscount; order.BidId = bid_id; order.SpecialInstructions = special_instructions; //order.TransactionResponseCode = response_code; //order.TransactionErrorMessage = response_error_message; order.Transaction = card_tk; //switch (response_code) //{ // case OrderController.RESPONSE_CODE_OK: order.TransactionStatus = OrderStatus.Payed; // break; // case OrderController.RESPONSE_CODE_ERROR: order.TransactionStatus = OrderStatus.NotPayed; // break; // default: order.TransactionStatus = OrderStatus.NotPayed; // break; //} // if (donation_id != 0) order.DonationId = donation_id; order.Last4Digits = last4_digits; order.ExpiryDate = expire_date; order.AppUserId = AppUserId; order.Save(); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName(@"order_id"); jsonWriter.WriteValue(order.OrderId); jsonWriter.WriteEndObject(); if (campaign_id != null && campaign_id != 0) { AppUserCampaign appUserCampaign = new AppUserCampaign(); appUserCampaign.AppUserId = AppUserId; appUserCampaign.CampaignId = campaign_id; appUserCampaign.Save(); } Offer offer = Offer.FetchByID(offer_id); // SupplierNotification.SendNotificationCloseBidToSupplier(order.OrderId, offer.SupplierId); AppSupplier supplier = AppSupplier.FetchByID(offer.SupplierId); if (supplier != null && supplier.StatusJoinBid == true) { supplier.MaxWinningsNum = (supplier.MaxWinningsNum > 0 ? supplier.MaxWinningsNum - 1 : 0); if (supplier.MaxWinningsNum == 0) { SupplierNotification.SendNotificationMaxAutoModeMessage(supplier.SupplierId); supplier.StatusJoinBid = false; } supplier.Save(); } } } } catch (Exception) { RespondError(Response, HttpStatusCode.InternalServerError, @"db-error"); } } }
protected async void ButtonValidateLinks_Click(object sender, EventArgs e) { bool hasError = false; HttpClient client = new HttpClient(); string apiAddress = ConfigurationManager.AppSettings["WebApiUrl"].ToString(); List <SupplierNotification> supplierNotificationList = new List <SupplierNotification>(); SupplierNotification supplierNotification = new SupplierNotification(); int optionId = Convert.ToInt32(DropDownListOption.SelectedValue); if (Convert.ToInt32(DropDownListInsightSupplier.SelectedValue) != Convert.ToInt32(allId)) { //string supplierDirectoryPath = "C:\\Development\\SPARInsightManagement\\Trunk\\Source\\Document\\SupplierLinks\\3M";//insightSupplier.SupplierDirectoryPath; //string supplierFolder = "3M";//insightSupplier.SupplierFolder; InsightSupplier insightSupplier = InsightSupplier.GetInsightSupplierByInsightSupplierId(Convert.ToInt32(DropDownListInsightSupplier.SelectedValue)); supplierNotification = new SupplierNotification(); supplierNotification.InsightSupplierId = insightSupplier.InsightSupplierId; supplierNotification.OptionId = optionId; supplierNotification.FolderPath = Path.Combine(insightSupplier.SupplierDirectoryPath, insightSupplier.SupplierFolder); supplierNotificationList = new List <SupplierNotification>(); supplierNotificationList.Add(supplierNotification); string supplierNotificationJSON = JsonConvert.SerializeObject(supplierNotificationList, Formatting.Indented); HttpContent httpContent = new StringContent(supplierNotificationJSON, System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(apiAddress, httpContent); if (response.IsSuccessStatusCode) { string responseString = await response.Content.ReadAsStringAsync(); List <SupplierNotification> supplierNotificationReturnList = JsonConvert.DeserializeObject <List <SupplierNotification> >(responseString); Guid batchId = Guid.NewGuid(); foreach (SupplierNotification supplierNotificationReturn in supplierNotificationReturnList) { SupplierNotification SupplierNotification = new SupplierNotification(); supplierNotification.InsightSupplierId = supplierNotificationReturn.InsightSupplierId; supplierNotification.OptionId = supplierNotificationReturn.OptionId; supplierNotification.FolderPath = supplierNotificationReturn.FolderPath; supplierNotification.File = supplierNotificationReturn.File; supplierNotification.IsValid = supplierNotificationReturn.IsValid; supplierNotification.Note = supplierNotificationReturn.Note; supplierNotification.FileModifiedDate = supplierNotificationReturn.FileModifiedDate; supplierNotification.FileSize = supplierNotificationReturn.FileSize; supplierNotification.BatchId = batchId; supplierNotification.ModifiedUser = Context.User.Identity.GetUserName(); supplierNotification.Save(); if (supplierNotificationReturn.IsValid == false) { hasError = true; } } if (hasError == true) { GridViewResult.DataSource = SupplierNotification.GetSupplierNotificationListByBatchId(batchId); GridViewResult.DataBind(); LabelBatch.Text = String.Format("{0} - {1}", "Batch", batchId); ButtonEmailLinks.Text = String.Format("{0}", "Email below Batch"); } else { LabelBatch.Text = String.Format("{0} - {1}", "Batch", batchId); ButtonEmailLinks.Text = String.Format("{0}", "Email below Batch"); ButtonEmailLinks.Enabled = true; } } } else { supplierNotificationList = new List <SupplierNotification>(); IEnumerable <InsightSupplier> insightSupplierList = InsightSupplier.GetInsightSupplierList(); foreach (InsightSupplier insightSupplier in insightSupplierList) { supplierNotification = new SupplierNotification(); supplierNotification.InsightSupplierId = insightSupplier.InsightSupplierId; supplierNotification.OptionId = optionId; supplierNotification.FolderPath = Path.Combine(insightSupplier.SupplierDirectoryPath, insightSupplier.SupplierFolder); supplierNotificationList.Add(supplierNotification); } string supplierNotificationJSON = JsonConvert.SerializeObject(supplierNotificationList, Formatting.Indented); HttpContent httpContent = new StringContent(supplierNotificationJSON, System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(apiAddress, httpContent); if (response.IsSuccessStatusCode) { string responseString = await response.Content.ReadAsStringAsync(); List <SupplierNotification> supplierNotificationReturnList = JsonConvert.DeserializeObject <List <SupplierNotification> >(responseString); Guid batchId = Guid.NewGuid(); foreach (SupplierNotification supplierNotificationReturn in supplierNotificationReturnList) { SupplierNotification SupplierNotification = new SupplierNotification(); supplierNotification.InsightSupplierId = supplierNotificationReturn.InsightSupplierId; supplierNotification.OptionId = supplierNotificationReturn.OptionId; supplierNotification.FolderPath = supplierNotificationReturn.FolderPath; supplierNotification.File = supplierNotificationReturn.File; supplierNotification.IsValid = supplierNotificationReturn.IsValid; supplierNotification.Note = supplierNotificationReturn.Note; supplierNotification.FileModifiedDate = supplierNotificationReturn.FileModifiedDate; supplierNotification.FileSize = supplierNotificationReturn.FileSize; supplierNotification.BatchId = batchId; supplierNotification.ModifiedUser = Context.User.Identity.GetUserName(); supplierNotification.Save(); if (supplierNotificationReturn.IsValid == false) { hasError = true; } } if (hasError == true) { GridViewResult.DataSource = SupplierNotification.GetSupplierNotificationListByBatchId(batchId); GridViewResult.DataBind(); } else { LabelBatch.Text = String.Format("{0} - {1}", "Batch", batchId); ButtonEmailLinks.Text = String.Format("{0} - {1}", "Email Batch", batchId); ButtonEmailLinks.Enabled = true; } } } }
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 AppUserId; if (IsAuthorizedRequest(Request, Response, true, out AppUserId)) { Response.ContentType = @"application/json"; try { JToken jt; string card_tk = null, expire_date = null, last4_digits = null, id_number = null, special_instructions = null; Int64 order_id = 0; bool is_payment_succesed = true; if (inputData.TryGetValue(@"is_payment_succesed", out jt)) { is_payment_succesed = jt.Value <bool>(); } if (is_payment_succesed) { if (inputData.TryGetValue(@"card_tk", out jt)) { card_tk = jt.Value <string>(); } if (inputData.TryGetValue(@"expire_date", out jt)) { expire_date = jt.Value <string>(); } if (inputData.TryGetValue(@"last4_digits", out jt)) { last4_digits = jt.Value <string>(); } if (inputData.TryGetValue(@"id_number", out jt)) { id_number = jt.Value <string>(); } } if (inputData.TryGetValue(@"order_id", out jt)) { order_id = jt.Value <Int64>(); } using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream)) { using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter)) { if (Order.FetchByOrderId(order_id) == null) { RespondError(Response, HttpStatusCode.BadRequest, @"order not exist"); } Order order = Order.FetchByOrderId(order_id); if (is_payment_succesed) { AppUserCard paymentToken = AppUserCard.FetchByAppUserId(AppUserId); if (paymentToken == null) { paymentToken = new AppUserCard(); } paymentToken.AppUserId = AppUserId; paymentToken.CardToken = card_tk; paymentToken.ExpiryDate = expire_date; paymentToken.Last4Digit = last4_digits; if (!String.IsNullOrEmpty(id_number)) { paymentToken.IdNumber = id_number; } paymentToken.Save(); order.Transaction = card_tk; order.Last4Digits = last4_digits; order.ExpiryDate = expire_date; order.AppUserId = AppUserId; order.UserPaySupplierStatus = UserPaymentStatus.Payed; } else { order.UserPaySupplierStatus = UserPaymentStatus.NotPayed; } order.Save(); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName(@"order_id"); jsonWriter.WriteValue(order.OrderId); jsonWriter.WriteEndObject(); long supplierId = 0; // need to update from offer SupplierNotification.SendNotificationCloseBidToSupplier(order.OrderId, supplierId); AppSupplier supplier = AppSupplier.FetchByID(supplierId); if (supplier != null && supplier.StatusJoinBid == true) { supplier.MaxWinningsNum = (supplier.MaxWinningsNum > 0 ? supplier.MaxWinningsNum - 1 : 0); if (supplier.MaxWinningsNum == 0) { SupplierNotification.SendNotificationMaxAutoModeMessage(supplier.SupplierId); supplier.StatusJoinBid = false; } supplier.Save(); } } } } catch (Exception) { RespondError(Response, HttpStatusCode.InternalServerError, @"db-error"); } } }