public UsersController( ApplicationRepository appRepo, AdminRepository adminRepo, IModelMetadataProvider metadataProvider, ILogger <UsersController> logger, IOptions <GlobalOptions> options, IServiceProvider serviceProvider, IEmailSender emailSender, EmailTemplatesProvider emailTemplates, IStringLocalizer <Strings> localizer, ITenantIdAccessor tenantIdAccessor, IBlobService blobService) : base(logger, localizer) { _appRepo = appRepo; _adminRepo = adminRepo; _tenantIdAccessor = tenantIdAccessor; _blobService = blobService; _metadataProvider = metadataProvider; _logger = logger; _emailSender = emailSender; _emailTemplates = emailTemplates; _options = options.Value; _localizer = localizer; // we use this trick since this is an optional dependency, it will resolve to null if // the embedded identity server is not enabled _userManager = (UserManager <EmbeddedIdentityServerUser>)serviceProvider.GetService(typeof(UserManager <EmbeddedIdentityServerUser>)); }
public bool Add(Order order) { foreach (CartItem item in Cart.Items) { order.Items.Add(new OrderItem { ProductId = item.Product.Id, Quantity = item.Quantity, UnitPrice = item.Product.CalculatedPrice.PriceFinalUah }); } order.Status = Status.Pending; order.CreationDate = DateTime.Now.ToUkrainianTimeZone(); orderRepository.Add(order); try { var templatesProvider = new EmailTemplatesProvider(productRepository); UnitOfWork.Commit(); Task.Factory.StartNew(() => { var message = new NotificationMessage { EmailTemplate = templatesProvider.GetCustomerOrderTemplate(order.User, order.Total), To = new[] { order.Email } }; NotificationManager.Current.Notify(message); message = new NotificationMessage { EmailTemplate = templatesProvider.GetSalesTemplate(order), To = new[] { Constants.SalesEmail } }; NotificationManager.Current.Notify(message); }).ContinueWith(obj => UnitOfWork.Dispose()); } catch (Exception e) { Logger.Error(e); } RemoveCart(); return(true); }