public async Task <System.Web.Mvc.ActionResult> BookingReceipt(string error_code, string token, int?canceledBookingID = null) { var userID = User.Identity.GetUserId(); var bookingService = this.Service <IBookingReceiptService>(); // If the customer cancel the booking, delete it and redirect him to homepage if (canceledBookingID != null) { var bookingReceipt = bookingService.Get(br => br.CustomerID == userID && br.ID == canceledBookingID && br.IsPending == true).FirstOrDefault(); if (bookingReceipt == null) { return(new HttpStatusCodeResult(400, "Invalid request")); } bookingService.Delete(bookingReceipt); return(RedirectToAction("Index", "Home")); } // If the transaction went smoothy, check the returned info + MD5 token var info = new RequestCheckOrderTestTemplate { Token = token }; var objNLCheckout = new APICheckoutV3(); var result = objNLCheckout.GetTransactionDetail(info); if (result.errorCode == "00") { // Try to get the bookingReceiptID try { var bookingID = int.Parse(result.order_code); var bookingReceipt = bookingService.Get(br => br.CustomerID == userID && br.ID == bookingID && br.IsPending == true).FirstOrDefault(); if (bookingReceipt == null) { return(new HttpStatusCodeResult(400, "Invalid request")); } bookingReceipt.IsPending = false; bookingService.Update(bookingReceipt); // Send alert email SystemService sysService = new SystemService(); await sysService.SendBookingAlertEmailToCustomer(bookingReceipt); await sysService.SendBookingAlertEmailToProvider(bookingReceipt); return(View("~/Areas/Customer/Views/Booking/BookingReceipt.cshtml", bookingReceipt)); } catch (FormatException e) { return(new HttpStatusCodeResult(400, "Invalid request")); } } return(new HttpStatusCodeResult(400, "Invalid request")); }
public async System.Threading.Tasks.Task <ActionResult> Success(string error_code, string token) { // Check the returned info + MD5 token var info = new RequestCheckOrderTestTemplate { Token = token }; var objNLCheckout = new APICheckoutV3(); var result = objNLCheckout.GetTransactionDetail(info); if (result.errorCode == "00") { // Try to get the new IsProviderUntil datetime try { // Separate the userID and IsProviderUntil Datetime from order_code var words = result.order_code.Split(new[] { " - " }, StringSplitOptions.None); if (words.Length != 2) { return(new HttpStatusCodeResult(400, "Invalid request")); } var userID = words[0]; // Get current user var userService = this.Service <IUserService>(); var user = await userService.GetAsync(userID); // Validate the user if (user == null) { return(new HttpStatusCodeResult(400, "Invalid request")); } var isProviderUntil = DateTime.Parse(words[1]); // Validate the new datetime if (isProviderUntil < DateTime.Now) { return(new HttpStatusCodeResult(400, "Invalid request")); } user.IsProviderUntil = isProviderUntil; // Add role provider if the user havent already had that role if (user.AspNetRoles.All(r => r.Name != "Provider")) { var providerRole = await this.Service <IRoleService>().GetAsync("2"); user.AspNetRoles.Add(providerRole); } userService.Update(user); // Send alert email var sysService = new SystemService(); await sysService.SendBecomeProviderAlertEmail(user.Email, user); return(View("~/Areas/Customer/Views/BecomeProvider/Success.cshtml", user)); } catch (FormatException e) { return(new HttpStatusCodeResult(400, "Invalid request")); } } return(new HttpStatusCodeResult(400, "Invalid request")); }