public ActionResult ForgotPassword(CustomerForgotPasswordViewModel model) { if (ModelState.IsValid) { var customer = db.Customers.Where(q => q.Email == model.Email).FirstOrDefault(); if (customer == null) { ModelState.AddModelError("Email", "Email is not correct"); return(View(model)); } else if (customer.DeletedAt != null) { ModelState.AddModelError("Email", "Account locked"); return(View(model)); } customer.ResetPasswordToken = CommonHelper.GenerateToken(6); while (db.Customers.Where(q => q.ResetPasswordToken == customer.ResetPasswordToken && q.DeletedAt == null).FirstOrDefault() != null) { customer.ResetPasswordToken = CommonHelper.GenerateToken(6); } customer.TokenExipredAt = DateTime.Now.AddMinutes(30); db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); model.Url = CommonHelper.GetBaseUrl() + Url.Action("ResetPassword") + "?token=" + customer.ResetPasswordToken; EmailHandler.Handle(model, model.Email, "Reset Password", "Views/Customer/Template/ForgotPasswordTemplate.cshtml"); return(Redirect(Request.UrlReferrer.ToString())); } return(View(model)); }
public ActionResult UpdateStatus(int id, UpdateOrderStatus model) { if (ModelState.IsValid) { int currentStaffId = ((Staff)Session["Staff"]).Id; var order = db.Orders.Where(q => q.Id == id).FirstOrDefault(); if (order == null) { return(NotFound()); } else if ((order.StaffId != null && order.StaffId != currentStaffId) || model.Status == App.Models.Order.PROCESSING || model.Status == App.Models.Order.WANT_TO_CANCEL || order.Status == App.Models.Order.RECEIVED || order.Status == App.Models.Order.CANCELED) { return(BadRequest()); } order.StaffId = currentStaffId; order.Message = order.Message ?? model.Message; order.Status = model.Status; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); EmailHandler.Handle(order, order.Customer.Email, "Detail about order " + order.Code, "Areas/Admin/Views/Orders/Template/OrderTemplate.cshtml"); // Transfer money back if status is canceled if (order.Status == App.Models.Order.CANCELED) { var customer = db.Customers.Where(q => q.Id == order.CustomerId).First(); PaymentService.SendPayout("Order is canceled", new List <PayoutItem>() { new PayoutItem() { recipient_type = (customer.CreditCard != null ? PayoutRecipientType.PAYPAL_ID : PayoutRecipientType.EMAIL), amount = new Currency { value = order.GrandTotal.ToString(), currency = "USD" }, receiver = customer.CreditCard ?? customer.Email, note = "Money of order #" + order.Code + " is sent back", sender_item_id = "payout_" + order.Id, } }); } return(Success(new { Id = order.Id, Status = order.Status, StaffName = order.Staff.Name })); } return(BadRequest()); }
public async Task Get() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.SetBasePath(Directory.GetCurrentDirectory()); configurationBuilder.AddJsonFile(Directory.GetCurrentDirectory() + @"\..\..\..\..\ALR.Console\appSettings.json", optional: false, reloadOnChange: true); configurationBuilder.AddJsonFile(Directory.GetCurrentDirectory() + @"\..\..\..\..\ALR.Console\appsettings.Secrets.json", optional: false, reloadOnChange: true); var config = configurationBuilder.Build(); var handler = new EmailHandler(config, new Logger <EmailHandler>(NullLoggerFactory.Instance)); await handler.Handle(new SendEmailReport( new List <TorrentDescriptor>() { new TorrentDescriptor() { Name = "Test!" } } ), CancellationToken.None); }
public Customer SaveCustomer(CheckoutViewModel model, int?id) { Customer customer = db.Customers.Where(q => q.Email == model.Email).FirstOrDefault(); if (customer == null) { string password = CommonHelper.RandomString(12).ToLower(); customer = db.Customers.Add(new Customer() { Name = model.Name, Password = Hashing.HashPassword(password), Email = model.Email, Address = model.Address, Phone = model.Phone, Avatar = "/Content/Client/img/others/blank-avatar.png", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }); var newModel = new NewAccountViewModel() { Name = model.Name, Email = model.Email, Password = password, LoginUrl = CommonHelper.GetBaseUrl() + Url.Action("Login", "Customer"), }; Task.Factory.StartNew(() => { EmailHandler.Handle(newModel, newModel.Email, "New Account", "Views/Customer/Template/NewAccountTemplate.cshtml"); }); } else { customer.Name = model.Name; customer.Email = model.Email; customer.Address = model.Address; customer.Phone = model.Phone; db.Entry(customer).State = System.Data.Entity.EntityState.Modified; } return(customer); }