public async Task <IActionResult> Edit(int id, [Bind("UserID,TransactionRef,PaymentStatus,Amount,DateCreated,PaymentType,ActivityID,IsAttended,Id")] Booking booking) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser == null || id != booking.Id) { return(NotFound()); } if (currentUser.IsViewOnly) { return(Forbid()); } if (ModelState.IsValid) { try { _context.Update(booking); await _context.SaveChangesAsync(); // send email notification if (booking.PaymentType == PaymentType.Cash && booking.PaymentStatus == PaymentStatus.Successful) { await _emailHelper.SendCashBookingSuccessfulEmailAsync(id); } else if (booking.PaymentStatus == PaymentStatus.Failed) { await _emailHelper.SendPaymentFailedEmailAsync(id); } } catch (DbUpdateConcurrencyException) { if (!BookingExists(booking.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ActivityID"] = new SelectList(_context.Activities, "Id", "Title", booking.ActivityID); return(View(booking)); }
public async Task <IActionResult> Create([Bind("AspId,FirstName,MiddleName,LastName,Email,PhoneNumber,IsViewOnly,AgeRange,Id")] User user) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser.IsViewOnly) { return(Forbid()); } var password = "******"; if (ModelState.IsValid) { var identityUser = new IdentityUser { UserName = user.Email, Email = user.Email }; var result = await _userManager.CreateAsync(identityUser, password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(identityUser); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = identityUser.Id, code = code }, protocol: Request.Scheme); user.AspId = identityUser.Id; _context.Add(user); await _context.SaveChangesAsync(); await _emailSender.SendEmailAsync(user.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); return(RedirectToAction(nameof(Index))); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(user)); }
public async Task <IActionResult> Create([Bind("Name,Value,Id")] Setting setting) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser.IsViewOnly) { return(Forbid()); } if (ModelState.IsValid) { _context.Add(setting); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(setting)); }
public async Task <IActionResult> Create([Bind("Name,Address,PictureUrl,ContactPhone,MapUrl,Coordinate,Id")] Location location) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser.IsViewOnly) { return(Forbid()); } if (ModelState.IsValid) { _context.Add(location); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(location)); }
public async Task <IActionResult> Create([Bind("Title,Description,PictureUrl,Capacity,StartDate,EndDate,Amount,HouseKeepingInfo,IsActive,LocationID,ActivityTypeID,Id")] Activity activity) { var currentUser = HttpContext.Session.Get <User>(Constants.SessionKeyUser); if (currentUser?.IsViewOnly ?? true) { return(Forbid()); } if (ModelState.IsValid) { _context.Add(activity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ActivityTypeID"] = new SelectList(_context.ActivityTypes, "Id", "Name", activity.ActivityTypeID); ViewData["LocationID"] = new SelectList(_context.Locations, "Id", "Name", activity.LocationID); return(View(activity)); }
private async Task LogVisit() { var user = HttpContext.Session.Get <User>(Constants.SessionKeyUser); var remoteIpAddress = HttpContext.Features.Get <IHttpConnectionFeature>()?.RemoteIpAddress.ToString(); var visitor = new Visitor() { Date = DateTime.Now, Page = Page.Home, IpAddress = remoteIpAddress, UserId = user?.Id }; _context.Visitors.Add(visitor); await _context.SaveChangesAsync(); }
public async Task <IActionResult> Verify([FromBody] VerificationRequest request) { if (ModelState.IsValid) { var auth = $"Bearer {_config.SecretKey}"; var response = await RestClient.GetJsonAsync <PaystackVerificationResponse>(auth, _config.VerifyUrl, request.TransactionRef); if (response == null) { return(Json(null)); } var booking = _context.Bookings.SingleOrDefault(x => x.TransactionRef == request.TransactionRef); if (booking != null) { var resp = new Response(); if (response.Data != null && "success".Equals(response.Data.Status)) { booking.PaymentStatus = PaymentStatus.Successful; resp.Code = "00"; resp.Description = "Your payment has been confirmed successful!"; } else { booking.PaymentStatus = PaymentStatus.Failed; resp.Code = "XX"; resp.Description = "Your payment failed. Please try again."; } booking.DateUpdated = DateTime.UtcNow.AddHours(1); _context.Bookings.Update(booking); await _context.SaveChangesAsync(); await _emailHelper.SendCashBookingSuccessfulEmailAsync(booking.Id); return(Json(resp)); } else { var donation = _context.Donations.SingleOrDefault(x => x.TransactionRef == request.TransactionRef); if (donation != null) { var resp = new Response(); if (response.Data != null && "success".Equals(response.Data.Status)) { donation.PaymentStatus = PaymentStatus.Successful; resp.Code = "00"; resp.Description = "Your donation has been confirmed successful. Thank you!"; } else { donation.PaymentStatus = PaymentStatus.Failed; resp.Code = "XX"; resp.Description = "Your payment failed. Please try again."; } donation.DateUpdated = DateTime.UtcNow.AddHours(1); _context.Donations.Update(donation); await _context.SaveChangesAsync(); return(Json(resp)); } } } return(Json(null)); }