public async Task <IActionResult> OnPostAsync() { var paramToUpdate = await _context.BillingParams.FindAsync(1); if (!ModelState.IsValid) { return(Page()); } if (paramToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <BillingParam>( paramToUpdate, "BillingParam", b => b.MinuteCost, b => b.TimeCoef, b => b.StartTime, b => b.EndTime)) { await _context.SaveChangesAsync(); return(RedirectToPage("/Index")); } return(Page()); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { var emptyExpr = new Expr(); Stopwatch stopWatch = new Stopwatch(); if (await TryUpdateModelAsync <Expr>( emptyExpr, "Expr", s => s.Expression)) { stopWatch.Start(); try { var result = new DataTable().Compute(emptyExpr.Expression, null); emptyExpr.Result = result.ToString(); } catch (Exception ex) { emptyExpr.Result = ex.Message; } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = ts.TotalMilliseconds.ToString(); emptyExpr.TimeSpan = elapsedTime; var user = await _userManager.GetUserAsync(User); emptyExpr.User = user; BillingParam billingparam = await _context.BillingParams.FirstOrDefaultAsync(b => b.BillingParamID == 1); decimal minutecost = billingparam.MinuteCost; DateTime starttime = billingparam.StartTime; DateTime endtime = billingparam.EndTime; double timecoef = billingparam.TimeCoef; if (DateTime.UtcNow.TimeOfDay > starttime.TimeOfDay && DateTime.UtcNow.TimeOfDay < endtime.TimeOfDay) { emptyExpr.Cost = (double)minutecost * timecoef * ts.TotalMilliseconds / 1000 / 60; } else { emptyExpr.Cost = (double)minutecost * ts.TotalMilliseconds / 1000 / 60; } _context.Expressions.Add(emptyExpr); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(Page()); }
public async Task <IActionResult> OnPostAsync() { var emptyPayment = new Payment(); if (await TryUpdateModelAsync <Payment>( emptyPayment, "payment", // Prefix for form value. p => p.UserId, p => p.PaymentSum, p => p.PaymentDate)) { _context.Payments.Add(emptyPayment); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Expr = await _context.Expressions.FindAsync(id); if (Expr != null) { _context.Expressions.Remove(Expr); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Payment = await _context.Payments.FindAsync(id); if (Payment != null) { _context.Payments.Remove(Payment); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }