public ActionResult Index() { ViewBag.Message = string.Empty; DiscountTransaction transaction = new DiscountTransaction(); var google = new GoogleSheetsHelper(); Session["templates"] = google.ReadSMSTemplates(true); Session["reasons"] = google.ReadDiscontReasons(true); Session["names"] = google.ReadPCCNames(true); //Session["enabletimer"] = false; ViewData["SMSTemplates"] = Transform(Session["templates"] as IList <string>); ViewData["DiscountReasons"] = Transform(Session["reasons"] as IList <string>); ViewData["PCCNames"] = Transform(Session["names"] as IList <string>); transaction.MessageTemplate = Transform(Session["templates"] as IList <string>).FirstOrDefault().Text; return(View(transaction)); }
public void CreateTransaction(DiscountTransaction transaction) { try { string sheetName = System.Configuration.ConfigurationManager.AppSettings["TransactionsSheetName"]; var range = $"{sheetName}!A:N"; var valueRange = new ValueRange(); var oblist = new List <object>() { transaction.CustomerName, transaction.CustomerEmail, transaction.MobileNumber, transaction.UserEmail, transaction.PCCName, transaction.BillNo, transaction.BillValue, transaction.Discount, transaction.BilledValue, transaction.DiscountReason, transaction.OTP, transaction.MessageTemplate, transaction.BilledDateTime.ToString("yyyy/MM/dd HH:mm:ss"), transaction.ValidationStatus }; valueRange.Values = new List <IList <object> > { oblist }; var appendRequest = _sheetsService.Spreadsheets.Values.Append(valueRange, _spreadsheetId, range); appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED; var appendReponse = appendRequest.Execute(); } catch (AggregateException err) { foreach (var errInner in err.InnerExceptions) { Console.WriteLine(errInner); //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary } } }
//not used public void UpdateTransaction(DiscountTransaction transaction) { try { var lastrow = GetLastRow(); string sheetName = System.Configuration.ConfigurationManager.AppSettings["TransactionsSheetName"]; var range = $"{sheetName}!N" + lastrow; var valueRange = new ValueRange(); var oblist = new List <object>() { transaction.ValidationStatus }; valueRange.Values = new List <IList <object> > { oblist }; var updateRequest = _sheetsService.Spreadsheets.Values.Update(valueRange, _spreadsheetId, range); updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED; var appendReponse = updateRequest.Execute(); } catch (AggregateException err) { foreach (var errInner in err.InnerExceptions) { Console.WriteLine(errInner); //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary } } }
public async Task AddDiscount(DiscountViewModel newdiscount) { DiscountPeriods item = new DiscountPeriods(); item.ItemId = newdiscount.ItemId; item.FromDate = newdiscount.FromDate; item.CompanyId = newdiscount.CompanyId; item.Name = newdiscount.Name; item.ToDate = newdiscount.ToDate; item.FromTime = newdiscount.FromTime; item.ToTime = newdiscount.ToTime; item.CreatedAt = DateTime.Now; item.UpdatedAt = DateTime.Now; item.IsActive = true; item.IsDelete = false; await context.DiscountPeriods.AddAsync(item); await context.SaveChangesAsync(); foreach (var list in newdiscount.DaysIdList) { DiscountTransaction transaction = new DiscountTransaction(); transaction.DiscountPeriodId = item.Id; transaction.DayId = list; await context.DiscountTransaction.AddAsync(transaction); await context.SaveChangesAsync(); } }
public async Task UpdateDiscount(DiscountViewModel newdiscount, int id) { var result = await context.DiscountPeriods.Include(x => x.DiscountTransaction) .FirstOrDefaultAsync(e => e.Id == id); if (result != null) { var discountTransaction = await context.DiscountTransaction.Where(x => x.DiscountPeriodId == id).ToListAsync(); if (discountTransaction != null) { context.DiscountTransaction.RemoveRange(discountTransaction); await context.SaveChangesAsync(); foreach (var list in newdiscount.DaysIdList) { DiscountTransaction transaction = new DiscountTransaction(); transaction.DiscountPeriodId = result.Id; transaction.DayId = list; await context.DiscountTransaction.AddAsync(transaction); await context.SaveChangesAsync(); } } result.FromDate = newdiscount.FromDate; result.Name = newdiscount.Name; result.ToDate = newdiscount.ToDate; result.FromTime = newdiscount.FromTime; result.ToTime = newdiscount.ToTime; context.DiscountPeriods.Update(result); await context.SaveChangesAsync(); } }
public IList <DiscountTransaction> ReadTransactions(bool IsFirstRowHeader) { IList <DiscountTransaction> transactions = new List <DiscountTransaction>(); try { string sheetName = System.Configuration.ConfigurationManager.AppSettings["TransactionsSheetName"]; var range = $"{sheetName}!A:N"; SpreadsheetsResource.ValuesResource.GetRequest request = _sheetsService.Spreadsheets.Values.Get(_spreadsheetId, range); var response = request.Execute(); IList <IList <object> > values = response.Values; if (values != null && values.Count > 0) { if (IsFirstRowHeader) { values = values.Skip(1).ToList(); } foreach (var row in values) { DiscountTransaction transaction = new DiscountTransaction(); transaction.CustomerName = row[0].ToString(); transaction.CustomerEmail = row[1].ToString(); transaction.MobileNumber = row[2].ToString(); transaction.UserEmail = row[3].ToString(); transaction.PCCName = row[4].ToString(); transaction.BillNo = row[5].ToString(); transaction.BillValue = Convert.ToDouble(row[6].ToString()); transaction.Discount = Convert.ToDouble(row[7].ToString()); transaction.DiscountReason = row[9].ToString(); transaction.OTP = row[10].ToString(); transaction.MessageTemplate = row[11].ToString(); transaction.BilledDateTime = Convert.ToDateTime(row[12].ToString()); transaction.ValidationStatus = row[13].ToString(); transactions.Add(transaction); // Print columns A to F, which correspond to indices 0 and 4. //Console.WriteLine("{0} | {1} | {2} | {3} | {4} | {5}", row[0], row[1], row[2], row[3], row[4], row[5]); } } } catch (AggregateException err) { foreach (var errInner in err.InnerExceptions) { Console.WriteLine(errInner); //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary } } return(transactions.OrderByDescending(x => x.BilledDateTime).ToList()); }
public DiscountTransaction New(int receiptId, int discountId, int?itemId = null) { DiscountTransaction discountTransaction = new DiscountTransaction() { ReceiptId = receiptId, DiscountId = discountId, ItemId = itemId, Time = DateTime.Now }; unitOfWork.DiscountTransactions.Insert(discountTransaction); Save(); return(discountTransaction); }
public void UpdateMsgTemplate(DiscountTransaction transaction) { try { UpdateTransaction("L", transaction.MessageTemplate); } catch (AggregateException err) { foreach (var errInner in err.InnerExceptions) { Console.WriteLine(errInner); //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary } } }
// GET: DiscountTransactions/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DiscountTransaction discountTransaction = db.DiscountTransactions.Find(id); if (discountTransaction == null) { return(HttpNotFound()); } return(View(discountTransaction)); }
public ActionResult ApplyDiscount() { int id = Convert.ToInt32(Request.Form["id"]); decimal discountPercent = Convert.ToDecimal(Request.Form["discountPercent" + id]); if (discountPercent == null) { discountPercent = 0; } Discount discount = db.Discounts.Find(id); AspNetUser user = db.AspNetUsers.Where(m => m.UserName == discount.Username).FirstOrDefault(); decimal discountAmount = (discountPercent * discount.TotalAmount) / 100; user.Discount += discountAmount; DiscountTransaction discountTransaction = new DiscountTransaction { Amount = discount.TotalAmount, CardID = discount.CardID, DiscountAmount = discountAmount, DiscountID = Guid.NewGuid().ToString(), DiscountPercent = discountPercent, TimeStamp = DateTime.Now, Username = discount.Username, CardType = db.CardDetails.FirstOrDefault(m => m.CardID == discount.CardID).CardType }; db.DiscountTransactions.Add(discountTransaction); db.Entry(user).State = EntityState.Modified; db.Discounts.Remove(discount); try { db.SaveChanges(); } catch (Exception) { RedirectToAction("Index", new { message = "Something went WRONG!! Discount was not applied!" }); } return(RedirectToAction("Index", new { message = "Discount applied" })); }
private static ISubledgerTransaction BuildSubledgerTransaction(TransactionType type, TransactionStatus status, decimal amount) { ISubledgerTransaction subledgerTransaction = null; if (type == TransactionType.Invoice) { subledgerTransaction = new InvoiceTransaction(status, amount); } else if (type == TransactionType.Credit) { subledgerTransaction = new CreditTransaction(amount); } else if (type == TransactionType.JournalAr || type == TransactionType.JournalNar) { subledgerTransaction = new JournalTransaction(amount); } else if (type == TransactionType.Receipt) { subledgerTransaction = new ReceiptTransaction(amount); } else if (type == TransactionType.Overpayment) { subledgerTransaction = new OverpaymentTransaction(amount); } else if (type == TransactionType.CreditBalanceTransferCredit || type == TransactionType.CreditBalanceTransferDebit || type == TransactionType.Allocation) { subledgerTransaction = new CreditBalanceTransferTransaction(amount); } else if (type == TransactionType.Discount) { subledgerTransaction = new DiscountTransaction(amount); } else if (type == TransactionType.Repurchase) { subledgerTransaction = new RepurchaseTransaction(amount); } return(subledgerTransaction); }
public ActionResult Index(DiscountTransaction model) { ViewData["SMSTemplates"] = Transform(Session["templates"] as IList <string>); ViewData["DiscountReasons"] = Transform(Session["reasons"] as IList <string>); ViewData["PCCNames"] = Transform(Session["names"] as IList <string>); if (ModelState.IsValid && Session["UserEmail"] != null) { var google = new GoogleSheetsHelper(); model.UserEmail = Session["UserEmail"].ToString(); model.ValidationStatus = System.Configuration.ConfigurationManager.AppSettings["OTPVerificationPendingMsg"]; model.enableSubmitbtn = false; MSGWowHelper helper = new MSGWowHelper(); var messageTempalte = model.MessageTemplate. Replace(System.Configuration.ConfigurationManager.AppSettings["Customername"], model.CustomerName) .Replace(System.Configuration.ConfigurationManager.AppSettings["Discount"], model.Discount.ToString() + " ") .Replace(System.Configuration.ConfigurationManager.AppSettings["Discountreason"], model.DiscountReason) .Replace(System.Configuration.ConfigurationManager.AppSettings["Billvalue"], model.BillValue.ToString()); model.MessageTemplate = messageTempalte; google.CreateTransaction(model); var isOTPSent = helper.sendOTP(model.MobileNumber, messageTempalte); //var isOTPSent = true; if (isOTPSent) { ViewBag.Message = System.Configuration.ConfigurationManager.AppSettings["SuccessfulOTPMsg"]; //Session["enabletimer"] = true; model.enableValidatebtn = true; // model.enableResendbtn = true; Session["transaction"] = model; google.UpdateMsgTemplate(model); return(View(model)); //enable validate otp button , disabled resend } else { ViewBag.Message = System.Configuration.ConfigurationManager.AppSettings["FailureOTPMsg"]; model.enableValidatebtn = true; // Final fix // model.enableResendbtn = true; Session["transaction"] = model; //Should we wait for 30 sec or enable resend button ?? -> enable resend button , disabled validate otp btn return(View(model)); } } return(View(model)); }