public ReturnData AJAX_Submit(int idOrder, string name, string email, string phoneNumber, string bank, decimal amount, string paymentDate, string notes, string baseImage, string fnImage) { try { DataClassesDataContext db = new DataClassesDataContext(); DateTime myDate = DateTime.ParseExact(paymentDate, "yyyy-MM-dd HH:mm", System.Globalization.CultureInfo.InvariantCulture); TBOrder order = db.TBOrders.Where(x => !x.Deflag && x.IDOrder == idOrder).FirstOrDefault(); if (order == null) { return(ReturnData.MessageFailed("Order not found", null)); } TBPayment_Confirmation data = new TBPayment_Confirmation(); data.IDOrder = idOrder; data.ReferenceNumber = order.Reference; data.Name = name; data.Email = email; data.PhoneNumber = phoneNumber; data.Bank = bank; data.Amount = amount; data.PaymentDate = myDate; data.Notes = notes; if (baseImage != "" && fnImage != "") { System.Drawing.Image _image = WITLibrary.ConvertCustom.Base64ToImage(baseImage); _image.Save(HttpContext.Current.Server.MapPath("/assets/images/payment_confirmation/" + DateTime.Now.ToString("ddmmyy") + "_" + fnImage)); data.Image = DateTime.Now.ToString("ddmmyy") + "_" + fnImage; } db.TBPayment_Confirmations.InsertOnSubmit(data); //GANTI STATUS JADI AWAITING PAYMENT VERIFICATION order.IDOrderStatus = 13; db.SubmitChanges(); //INSERT LOG ORDER Class_Log_Order logOrder = new Class_Log_Order(); logOrder.Insert((int?)null, order.IDOrder, order.Reference, order.TBOrder_Status.Name, "Customer Payment Confirmation", order.TBCustomer.FirstName + ' ' + order.TBCustomer.LastName); //SEND EMAIL TO ADMIN using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/assets/email-template/admin-payment-notification.html"))) { string body = ""; body = reader.ReadToEnd(); body = body.Replace("{ReferenceCode}", data.ReferenceNumber); body = body.Replace("{CustomerName}", data.Name); body = body.Replace("{Name}", data.Name); body = body.Replace("{Email}", data.Email); body = body.Replace("{Date}", data.PaymentDate.ToString("dd/MM/yyyy hh:mm")); body = body.Replace("{Amount}", WITLibrary.ConvertString.ToCurrency(data.Amount.ToString())); body = body.Replace("{Bank}", data.Bank); body = body.Replace("{Notes}", data.Notes); string emailAdmin = db.TBConfigurations.Where(x => x.Name == "email_user").FirstOrDefault().Value; OurClass.SendEmail(emailAdmin, WebConfigurationManager.AppSettings["Title"] + " Confirm Payment for Order #" + data.ReferenceNumber, body, HttpContext.Current.Server.MapPath("/assets/images/payment_confirmation/" + DateTime.Now.ToString("ddmmyy") + "_" + fnImage)); } //SEND EMAIL KE CUSTOMER Class_Configuration _config = new Class_Configuration(); var emailLogo = _config.Dynamic_Get_EmailLogo(); using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/assets/email-template/template-email-paymentReceived.html"))) { string body = ""; body = reader.ReadToEnd(); body = body.Replace("{name}", name); body = body.Replace("{nomorInvoice}", order.Reference); body = body.Replace("{amount}", WITLibrary.ConvertString.ToCurrency(order.TotalPaid.ToString())); body = body.Replace("{owner}", order.TBPayment_Method.Owner); body = body.Replace("{account}", order.TBPayment_Method.AccountNumber); body = body.Replace("{bank}", order.TBPayment_Method.Bank); body = body.Replace("{title}", System.Configuration.ConfigurationManager.AppSettings["Title"]); body = body.Replace("{email_logo}", System.Configuration.ConfigurationManager.AppSettings["url"] + "/assets/images/email_logo/" + emailLogo); body = body.Replace("{shop_url}", System.Configuration.ConfigurationManager.AppSettings["url"]); OurClass.SendEmail(email, WebConfigurationManager.AppSettings["Title"] + " Order Notification", body, ""); } return(ReturnData.MessageSuccess("Order Confirmation submitted successfully", null)); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }
public ReturnData AJAX_AutoCancel() { try { DataClassesDataContext db = new DataClassesDataContext(); double autocancel = double.Parse(Dynamic_GetValue_AutoCancel()); var dataOrder = db.TBOrders.Where(x => !x.Deflag && x.TBOrder_Status.Paid == false && x.TBOrder_Status.Logable == false && x.TBOrder_Status.Delivery == false && x.TBOrder_Status.Shipped == false && x.TBOrder_Status.Restock == false && DateTime.Now >= x.DateInsert.AddHours(autocancel)); Class_Configuration _config = new Class_Configuration(); var emailLogo = _config.Dynamic_Get_EmailLogo(); if (dataOrder == null || dataOrder.Count() == 0) { return(ReturnData.MessageFailed("Data not found", null)); } else { foreach (var item in dataOrder) { if (item.IDVoucher != null) { item.TBVoucher.Used -= 1; } var ordDetail = db.TBOrder_Details.Where(x => x.IDOrder == item.IDOrder); foreach (var detail in ordDetail) { detail.TBProduct_Combination.Quantity += detail.Quantity; } item.IDOrderStatus = db.TBOrder_Status.Where(x => !x.Deflag && x.Paid == false && x.Logable == true && x.Delivery == false && x.Shipped == false && x.Restock == true).FirstOrDefault().IDOrderStatus; item.DateLastUpdate = DateTime.Now; //INSERT LOG ORDER Class_Log_Order logOrder = new Class_Log_Order(); logOrder.Insert((int?)null, item.IDOrder, item.Reference, item.TBOrder_Status.Name, "Autocancel By System ", item.TBCustomer.FirstName + ' ' + item.TBCustomer.LastName); using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/assets/email-template/template-email-canceled.html"))) { string body = ""; body = reader.ReadToEnd(); body = body.Replace("{name}", item.TBCustomer.FirstName); body = body.Replace("{amount}", item.TotalPaid.ToString()); body = body.Replace("{owner}", item.TBPayment_Method.Owner); body = body.Replace("{account}", item.TBPayment_Method.AccountNumber); body = body.Replace("{bank}", item.TBPayment_Method.Bank); if (item.InvoiceNumber == null) { body = body.Replace("{nomorInvoice}", item.Reference); } else { body = body.Replace("{nomorInvoice}", item.InvoiceNumber); } body = body.Replace("{title}", System.Configuration.ConfigurationManager.AppSettings["Title"]); body = body.Replace("{email_logo}", System.Configuration.ConfigurationManager.AppSettings["url"] + "/assets/images/email_logo/" + emailLogo); body = body.Replace("{shop_url}", System.Configuration.ConfigurationManager.AppSettings["url"]); OurClass.SendEmail(item.TBCustomer.Email, System.Web.Configuration.WebConfigurationManager.AppSettings["Title"] + " - Order Cancelled", body, ""); } } db.SubmitChanges(); return(ReturnData.MessageSuccess("Some Order cancelled automatically", null)); } } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }