public AccountManager(CustomerServiceProvider customerServiceProvider, ContactFactory contactFactory, MailManager mailManager, StorefrontContext storefrontContext) { CustomerServiceProvider = customerServiceProvider; ContactFactory = contactFactory; MailManager = mailManager; StorefrontContext = storefrontContext; }
public ManagerResponse <SubmitVisitorOrderResult, CommerceOrder> SubmitVisitorOrder(string userId, SubmitOrderInputModel inputModel) { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); var errorResult = new SubmitVisitorOrderResult { Success = false }; var response = CartManager.GetCart(userId, true); if (!response.ServiceProviderResult.Success || response.Result == null) { response.ServiceProviderResult.SystemMessages.ToList().ForEach(m => errorResult.SystemMessages.Add(m)); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null)); } var cart = (CommerceCart)response.ServiceProviderResult.Cart; if (cart.Lines.Count == 0) { errorResult.SystemMessages.Add(new SystemMessage { Message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Submit Order Has Empty Cart", "Cannot submit and order with an empty cart.") }); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, null)); } cart.Email = inputModel.UserEmail; var request = new SubmitVisitorOrderRequest(cart); RefreshCartOnOrdersRequest(request); errorResult = OrderServiceProvider.SubmitVisitorOrder(request); if (errorResult.Success && errorResult.Order != null && errorResult.CartWithErrors == null) { CartCacheHelper.InvalidateCartCache(userId); try { var wasEmailSent = MailManager.SendMail("PurchaseConfirmation", inputModel.UserEmail, string.Join(" ", cart.Parties.FirstOrDefault()?.FirstName, cart.Parties.FirstOrDefault()?.LastName), errorResult.Order.TrackingNumber, errorResult.Order.OrderDate, string.Join(", ", cart.Lines.Select(x => x.Product.ProductName)), cart.Total.Amount.ToCurrency(cart.Total.CurrencyCode)); if (!wasEmailSent) { var message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Could Not Send Email Error", "Sorry, the email could not be sent"); //errorResult.SystemMessages.Add(new SystemMessage(message)); } } catch (Exception ex) { Log.Error("Could not send Purchase Confirmation mail message", ex, this); var message = DictionaryPhraseRepository.Current.Get("/System Messages/Orders/Could Not Send Email Error", "Sorry, the email could not be sent"); errorResult.SystemMessages.Add(new SystemMessage(message)); } } errorResult.WriteToSitecoreLog(); return(new ManagerResponse <SubmitVisitorOrderResult, CommerceOrder>(errorResult, errorResult.Order as CommerceOrder)); }
public OrderManager(OrderServiceProvider orderServiceProvider, CartManager cartManager, CartCacheHelper cartCacheHelper, MailManager mailManager, StorefrontContext storefrontContext, AccountManager accountManager) { Assert.ArgumentNotNull(orderServiceProvider, nameof(orderServiceProvider)); Assert.ArgumentNotNull(cartManager, nameof(cartManager)); OrderServiceProvider = orderServiceProvider; CartManager = cartManager; CartCacheHelper = cartCacheHelper; MailManager = mailManager; StorefrontContext = storefrontContext; AccountManager = accountManager; }
public ManagerResponse <UpdatePasswordResult, bool> ResetUserPassword(ForgotPasswordInputModel inputModel) { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); Assert.ArgumentNotNullOrEmpty(inputModel.Email, nameof(inputModel.Email)); var result = new UpdatePasswordResult { Success = true }; var getUserResponse = GetUser(inputModel.Email); if (!getUserResponse.ServiceProviderResult.Success || getUserResponse.Result == null) { result.Success = false; foreach (var systemMessage in getUserResponse.ServiceProviderResult.SystemMessages) { result.SystemMessages.Add(systemMessage); } } else { try { var userIpAddress = HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : string.Empty; var provisionalPassword = Membership.Provider.ResetPassword(getUserResponse.Result.UserName, string.Empty); var wasEmailSent = MailManager.SendMail("ForgotPassword", inputModel.Email, userIpAddress, provisionalPassword); if (!wasEmailSent) { var message = DictionaryPhraseRepository.Current.Get("/System Messages/Accounts/Could Not Send Email Error", "Sorry, the email could not be sent"); result.Success = false; result.SystemMessages.Add(new SystemMessage { Message = message }); } } catch (Exception e) { result.Success = false; result.SystemMessages.Add(new SystemMessage { Message = e.Message }); } result.WriteToSitecoreLog(); } return(new ManagerResponse <UpdatePasswordResult, bool>(result, result.Success)); }