Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SmartaBusinessBuilder.Core.RepositoryInterfaces;
- using System.Linq;
- using System.Collections.Generic;
- using System;
- using SmartaBusinessBuilder.Core.Helpers;
- using System.IO;
- using SmartaBusinessBuilder.Encryption;
- using SmartaBusinessBuilder.Core.Enums;
- using SmartaBusinessBuilder.Core.ExtensionMethods;
- using System.Web.Mvc;
- using SmartaBusinessBuilder.Core.Exceptions;
- using SmartaBusinessBuilder.Core.Dashboard;
- using SmartaBusinessBuilder.Core.DashboardInterfaces;
- using Microsoft.Practices.ServiceLocation;
- using SmartaBusinessBuilder.ApplicationServices;
- using SmartaBusinessBuilder.Core.ModelBinders;
- namespace SmartaBusinessBuilder.Core.ViewModels
- {
- public class AccountModel
- {
- #region Fields
- #region Repository Fields
- private readonly IAccountRepository _accountRepository;
- private readonly IBundleRepository _bundleRepository;
- private readonly ISmartaUserRepository _userRepository;
- private readonly ISettingRepository _settingRepository;
- private readonly IPackageOrderRepository _orderRepository;
- private readonly ISmartaUserAccountSystemRepository _userAccountProductRepository;
- private readonly IAccountStatusRepository _accountStatusRepository;
- private readonly IEmailRepository _emailRepository;
- private readonly IAddressRepository _addressRepository;
- private readonly IProviderOutputRepository _outputRepository;
- private readonly ISmartaUserAccountSystemRepository _userAccountSystemRepository;
- private readonly IUserSystemPasswordRepository _userSystemPasswordRepository;
- private readonly IAccountSystemPasswordRepository _accountSystemRepository;
- private readonly ISystemRepository _systemRepository;
- private readonly IAdminLoginRepository _adminLoginRepository;
- #endregion
- private IAccounts _accounts;
- private IDomain _domain;
- private SmartaUser _user;
- private int _selectedAccountId;
- private SettingCollection _settingCollection;
- private List<SmartaUserAccountSystem> _userSystems;
- private IBusinessPlan _businessPlan;
- private IWebsiteBuilder _website;
- private ILegal _legal;
- private IList<AdminLoginValue> _adminValues;
- private IEmail _emailGateway;
- #endregion
- #region Properties
- public IList<SmartaUser> Users { get; private set; }
- public OrderModel OrderModel { get; private set; }
- public SettingCollection Setting
- {
- get
- {
- if (_settingCollection == null)
- _settingCollection = new SettingCollection(_settingRepository.GetAll());
- return _settingCollection;
- }
- }
- private List<SmartaUserAccountSystem> UserSystems { get; set; }
- private AdminLoginCollection BusinessPlanAdminValueCollection
- {
- get
- {
- return new AdminLoginCollection(AdminValueCollection.Where(a => a.AdminLoginTypeId == AdminLoginType.BusinessPlan).ToList());
- }
- }
- private IWebsiteBuilder WebsiteBuilder
- {
- get
- {
- if (_website == null)
- _website = ServiceLocator.Current.GetInstance<IWebsiteBuilder>("IWebsiteBuilder");
- return _website;
- }
- }
- private AdminLoginCollection WebsiteAdminValueCollection
- {
- get
- {
- return new AdminLoginCollection(AdminValueCollection.Where(a => a.AdminLoginTypeId == AdminLoginType.WebsiteBuilder).ToList());
- }
- }
- public string UniqueDomainName
- {
- get
- {
- return SelectedAccount.Domains.First().FullName;
- }
- }
- public bool AllowDomainSelection
- {
- get
- {
- return SelectedAccount.Domains.Where(d => d.DomainType.Id != (int)Enums.DomainType.Smarta).Count() > 1;
- }
- }
- public decimal Vat
- {
- get
- {
- string vat = Setting.Get(SettingType.Vat);
- return decimal.Parse(vat);
- }
- }
- public Account SelectedAccount
- {
- get
- {
- return _user.Accounts.First(a => a.Id == _selectedAccountId);
- }
- }
- public Bundle CurrentBundle
- {
- get
- {
- var order = SelectedAccount.Orders.Where(x => x.HasOrderLines).FirstOrDefault(o => o.OrderLines.Any(i => !i.Cancelled && i.IsBundle));
- var orderline = order.OrderLines.FirstOrDefault(i => i.IsBundle);
- return orderline != null ? orderline.Bundle : null;
- }
- }
- public IEnumerable<Product> SelectedAddOns
- {
- get
- {
- return SelectedAccount.AccountProducts.Where(ap => !CurrentBundle.IncludedProducts.Any(p => p.Id == ap.Product.Id)).Select(a => a.Product);
- }
- }
- public bool HasAddOns
- {
- get
- {
- return SelectedAddOns != null && SelectedAddOns.Count() > 0;
- }
- }
- private IEnumerable<SmartaUserAccountSystem> SelectedUserSystems
- {
- get
- {
- if (UserSystems != null)
- { return UserSystems.Where(u => u.SmartaUser.Id == SelectedUser.Id); }
- else
- { return new List<SmartaUserAccountSystem>(); }
- }
- }
- public IEnumerable<Bundle> Bundles { get; set; }
- public IEnumerable<Bundle> AvailableBundles
- {
- get
- {
- return Bundles.Where(b => b.Id != CurrentBundle.Id);
- }
- }
- public IEnumerable<Product> UnselectedAddOns
- {
- get
- {
- return CurrentBundle.AddOns.Where(a => !SelectedAddOns.Any(s => s.Id == a.Id));
- }
- }
- public bool CanChangeBundle
- {
- get
- {
- // We don't allow the user to downgrade so can only upgrade
- return CurrentBundle.Rank != Bundles.Max(b => b.Rank);
- }
- }
- public IList<SmartaUser> UsersOnAccount
- {
- get
- {
- return SelectedAccount.Users;
- }
- }
- public UserDetails UserDetails { get; set; }
- public UserPermissions UserPermissions { get; set; }
- public IList<System> Systems { get; private set; }
- public bool HasEmailAccountsRemaining
- {
- get
- {
- var acc = _accountRepository.Get(_selectedAccountId);
- var availableEmailAccounts = acc.AccountProducts.Where(p => p.Product.System.Id == (int)SmartaSystem.Email).Sum(x => x.Quantity);
- var userAccountSystems = _userAccountSystemRepository.GetBySystemAndAccount(SmartaSystem.Email, _selectedAccountId);
- var distinctUserCount = userAccountSystems.Where(a => a.System.Id == (int)SmartaSystem.Email).Distinct((lhs, rhs) => lhs.SmartaUser.Id == rhs.SmartaUser.Id, hash => hash.SmartaUser.Id.GetHashCode()).Count();
- return availableEmailAccounts > distinctUserCount;
- }
- }
- private AdminLoginCollection LegalAdminValueCollection
- {
- get
- {
- return new AdminLoginCollection(AdminValueCollection.Where(a => a.AdminLoginTypeId == AdminLoginType.LegalDocument).ToList());
- }
- }
- private ILegal Legal
- {
- get
- {
- if (_legal == null)
- _legal = ServiceLocator.Current.GetInstance<ILegal>("ILegal");
- return _legal;
- }
- }
- private AdminLoginCollection AccountsAdminValueCollection
- {
- get
- {
- return new AdminLoginCollection(AdminValueCollection.Where(a => a.AdminLoginTypeId == AdminLoginType.Accounts).ToList());
- }
- }
- public SmartaUser SelectedUser { get; private set; }
- public IEnumerable<Product> AddOns
- {
- get
- {
- return CurrentBundle.AddOns;
- }
- }
- #endregion
- #region Constructors
- public AccountModel(IAccountRepository accountRepository, ISmartaUserRepository userRepository, IBundleRepository bundleRepository, ISettingRepository settingRepository, IPackageOrderRepository orderRepository, ISmartaUserAccountSystemRepository userAccountProductRepository, IAccountStatusRepository accounStatusRepository, IEmailRepository emailRepository, ISmartaUserAccountSystemRepository userAccountSystemRepository, ISystemRepository systemRepository)
- {
- _accountRepository = accountRepository;
- _userRepository = userRepository;
- _bundleRepository = bundleRepository;
- _settingRepository = settingRepository;
- _orderRepository = orderRepository;
- _userAccountProductRepository = userAccountProductRepository;
- _accountStatusRepository = accounStatusRepository;
- _emailRepository = emailRepository;
- _systemRepository = systemRepository;
- _userAccountSystemRepository = userAccountSystemRepository;
- }
- public AccountModel(IAccountRepository accountRepository, ISmartaUserRepository userRepository, IBundleRepository bundleRepository, ISettingRepository settingRepository, IPackageOrderRepository orderRepository, ISmartaUserAccountSystemRepository userAccountProductRepository, IAccountStatusRepository accounStatusRepository, IEmailRepository emailRepository, SmartaUser user, int accountId, ISystemRepository systemRepository, ISmartaUserAccountSystemRepository userAccountSystemRepository, IAddressRepository addressRepository, IAccounts accounts, IDomain domain, IBusinessPlan businessPlan, IProviderOutputRepository outputRepository, IUserSystemPasswordRepository userSystemPasswordRepository, IAccountSystemPasswordRepository accountSystemRepository, IAdminLoginRepository adminLoginRepository)
- {
- _outputRepository = outputRepository;
- _accountRepository = accountRepository;
- _userRepository = userRepository;
- _bundleRepository = bundleRepository;
- _settingRepository = settingRepository;
- _orderRepository = orderRepository;
- _userAccountProductRepository = userAccountProductRepository;
- _accountStatusRepository = accounStatusRepository;
- _emailRepository = emailRepository;
- _systemRepository = systemRepository;
- _userAccountSystemRepository = userAccountSystemRepository;
- _addressRepository = addressRepository;
- _userSystemPasswordRepository = userSystemPasswordRepository;
- _accountSystemRepository = accountSystemRepository;
- _adminLoginRepository = adminLoginRepository;
- _accounts = accounts;
- _businessPlan = businessPlan;
- _domain = domain;
- _user = user;
- _selectedAccountId = accountId;
- Bundles = _bundleRepository.GetAll();
- OrderModel = new OrderModel(_settingRepository, _userRepository, _userAccountProductRepository, _accountStatusRepository);
- UserDetails = new UserDetails();
- SelectedUser = new SmartaUser();
- GetData();
- UserPermissions = new UserPermissions(Systems, HasEmailAccountsRemaining);
- }
- #endregion
- #region Properties
- #region Current Monthly Payment properties
- public decimal CurrentMonthlyPayment
- {
- get
- {
- var products = SelectedAccount.Orders.Sum(o => o.OrderLines.Where(l => !l.IsBundle && !l.Cancelled && l.Product.ProductPaymentTypeId == (int)Enums.PaymentType.Monthly).Sum(i => i.Quantity * i.Price));
- var bundle = SelectedAccount.Orders.Select(o => o.OrderLines.First(l => l.IsBundle && !l.Cancelled).Bundle.Price).First();
- return products + bundle;
- }
- }
- public string CurrentMonthlyPaymentDisplay
- {
- get
- {
- return CurrentMonthlyPayment.ToString("#0.00");
- }
- }
- public string CurrentMonthlyPaymentVat
- {
- get
- {
- return (CurrentMonthlyPayment * (Vat / 100)).ToString("#0.00");
- }
- }
- public string CurrentMonthlyPaymentTotal
- {
- get
- {
- return (CurrentMonthlyPayment * (1 + (Vat / 100))).ToString("#0.00");
- }
- }
- #endregion
- #region Additional License Costs
- public string AdditionalLicenseMonthlyCost
- {
- get
- {
- return GetAdditionalLicenseCost(true).ToString("0.00");
- }
- }
- public string AdditionalLicenseCost
- {
- get
- {
- return GetAdditionalLicenseCost(false).ToString("0.00");
- }
- }
- public string TotalAdditionalLicenseCost
- {
- get
- {
- return GetTotalAdditionalLicenseCost().ToString("0.00");
- }
- }
- #endregion
- #region Additional Add On Cost
- public string AdditionalAddOnCost
- {
- get
- {
- return GetAdditionalAddOnCost(false).ToString("0.00");
- }
- }
- public string AdditionalAddOnMonthlyCost
- {
- get
- {
- return GetAdditionalAddOnCost(true).ToString("0.00");
- }
- }
- public string TotalAdditionalAddOnMonthlyCost
- {
- get
- {
- return GetTotalAdditionalAddOnCost().ToString("0.00");
- }
- }
- #endregion
- #region New Monthly Payment properties
- public decimal NewMonthlyPayment
- {
- get
- {
- return OrderModel.TotalMonthlyCost + CurrentMonthlyPayment;
- }
- }
- public string NewMonthlyPaymentDisplay
- {
- get
- {
- return NewMonthlyPayment.ToString("#0.00");
- }
- }
- public string NewMonthlyPaymentVat
- {
- get
- {
- return (NewMonthlyPayment * (Vat / 100)).ToString("#0.00");
- }
- }
- public string NewMonthlyPaymentTotal
- {
- get
- {
- return (NewMonthlyPayment * (1 + (Vat / 100))).ToString("#0.00");
- }
- }
- public string OneOffCosts
- {
- get
- {
- return (GetTotalAdditionalAddOnCost() + GetTotalAdditionalLicenseCost()).ToString("0.00");
- }
- }
- public string Cost
- {
- get
- {
- return ((GetTotalAdditionalAddOnCost() + GetTotalAdditionalLicenseCost()) + ((GetTotalAdditionalAddOnCost() + GetTotalAdditionalLicenseCost()) * (Vat/100))).ToString("0.00");
- }
- }
- public string VatCost
- {
- get
- {
- return ((GetTotalAdditionalAddOnCost() + GetTotalAdditionalLicenseCost()) * (Vat/100)).ToString("0.00");
- }
- }
- #endregion
- #endregion
- #region Methods
- #region Public Methods
- public string BundleChange(int rank)
- {
- return rank < CurrentBundle.Rank ? "Downgrade" : "Upgrade";
- }
- public void CancelAccount()
- {
- // TODO : Need to control the cancellation of the account.
- CancelUserLevelAccess();
- // TODO : Get the account passwords (not user passwords) for account level provisioned providers. Cancel each of these...
- CancelAccountLevelAccess();
- // If the user has purchased a domain through Smarta then we need to effectively transfer the ownership. Here we should send them an email with their login details to enom to
- // maintain their domain. The domain will be moved to a magic folder whereby it will not be renewed automatically.
- CancelDomains();
- // TODO : We have a hardcoded value for commid here. Need to put this somewhere...
- DataPoster.Post(SmartaBusinessBuilderSettings.Settings.RentSoftUrlCancellation, string.Format("userid={0}&accountid={1}&commid=67", _user.Id, _selectedAccountId));
- var user = _userRepository.Get(_user.Id);
- user.Accounts.First(a => a.Id == _selectedAccountId).AccountStatus = new AccountStatus((int)Enums.AccountStatus.Cancelled);
- _userRepository.SaveOrUpdate(user);
- _userRepository.DbContext.CommitChanges();
- // Send Cancellation email
- CreateCancellationEmail();
- }
- public void GetUser(int id)
- {
- SelectedUser = _userRepository.Get(id);
- }
- public string BundleChange()
- {
- int rank = OrderModel.Order.OrderLines.First(o => o.IsBundle).Bundle.Rank;
- return BundleChange(rank);
- }
- public string OrderQuantity(int productId)
- {
- return OrderModel.OrderQuantityDisplay(productId);
- }
- public bool IsProductSelected(int id)
- {
- return OrderModel.IsProductSelected(id);
- }
- public bool CanAddProduct(int productId, int quantity)
- {
- var product = CurrentBundle.BundleProducts.First(p => p.Product.Id == productId);
- if (!product.CanAdd)
- return false;
- int? max = product.MaximumAllowed;
- return !max.HasValue || quantity < max.Value;
- }
- public bool CanAddProduct(int productId)
- {
- if (OrderModel == null || OrderModel.Order == null || !OrderModel.Order.HasOrderLines)
- return true;
- int cnt = OrderModel.Order.OrderLines.Count(o => !o.IsBundle && o.Product.Id == productId);
- return CanAddProduct(productId, cnt);
- }
- public void RemoveProduct(int id)
- {
- OrderModel.RemoveProduct(id);
- }
- public void AddProduct(int id)
- {
- OrderModel.AddOrder(CurrentBundle.AllProducts.First(p => p.Id == id));
- }
- public void DeleteAddOn(int id)
- {
- if (OrderModel.IsProductSelected(id))
- OrderModel.RemoveProduct(id);
- else
- OrderModel.AddNegativeOrder(CurrentBundle.AllProducts.First(p => p.Id == id));
- }
- /// <summary>
- /// Need to store the orders - new and cancelled orders as well as the AccountProducts
- /// </summary>
- public void Save()
- {
- var orders = _orderRepository.GetAllForAccount(_selectedAccountId);
- var user = _userRepository.Get(_user.Id);
- var account = user.Accounts.First(a => a.Id == _selectedAccountId);
- // Has user changed Bundle?
- if (OrderModel.Order.OrderLines.Any(ol => ol.IsBundle)
- && account.Orders.Select(o => o.OrderLines.First(l => l.IsBundle).Bundle.Id).First() != OrderModel.Order.OrderLines.First(ol => ol.IsBundle).Bundle.Id)
- {
- // Cancel the current bundle order line so we can then add the additional one later
- var bundleOrder = orders.First(o => o.OrderLines.Any(l => l.IsBundle));
- bundleOrder.OrderLines.First(l => l.IsBundle).Cancelled = true;
- // Remove products from previous bundle and add products for new bundle.
- foreach (var product in bundleOrder.OrderLines.First(l => l.IsBundle).Bundle.IncludedProducts)
- {
- account.DeleteProduct(product.Id);
- }
- // Add products from new bundle
- foreach (var product in OrderModel.Order.OrderLines.First(l => l.IsBundle).Bundle.IncludedProducts)
- {
- var quantity = OrderModel.Order.OrderLines.First(l => l.IsBundle).Bundle.GetIncludedProductCount(product.Id);
- account.AddProduct(product, quantity);
- }
- }
- // Delete Add Ons removed
- OrderModel.Order.OrderLines.Where(o => !o.IsBundle).Where(o => o.Cancelled).ToList().ForEach(o => account.DeleteProduct(o.ProductId));
- OrderModel.Order.OrderLines.Where(o => !o.IsBundle).Where(o => !o.Cancelled && o.Quantity > 0).ToList().ForEach(o => account.AddProduct(CurrentBundle.AllProducts.First(p => p.Id == o.ProductId), o.Quantity));
- OrderModel.Order.OrderLines.Where(o => !o.IsBundle).Where(o => !o.Cancelled && o.Quantity < 0).ToList().ForEach(o => account.DeleteProduct(o.ProductId));
- account.AddOrder(OrderModel.Order);
- using (_orderRepository.DbContext.BeginTransaction())
- {
- try
- {
- foreach (var order in orders)
- {
- order.Account = account;
- _orderRepository.SaveOrUpdate(order);
- _orderRepository.DbContext.CommitChanges();
- }
- _userRepository.SaveOrUpdate(user);
- _userRepository.DbContext.CommitChanges();
- _orderRepository.DbContext.CommitTransaction();
- }
- catch
- {
- _orderRepository.DbContext.RollbackTransaction();
- throw;
- }
- }
- }
- public int QuantityBought(int productId)
- {
- var quantityPreviouslyAdded = 0;
- var _selectedAccount = SelectedAccount;
- var existingLines = _selectedAccount.Orders.SelectMany(o => o.OrderLines.Where(ol => !ol.IsBundle && ol.ProductId == productId));
- if (existingLines != null && existingLines.Count() > 0)
- quantityPreviouslyAdded = existingLines.First(ol => ol.ProductId == productId).Quantity;
- var linesNewlyAdded = OrderModel.IsOrderEmpty ? null : OrderModel.Order.OrderLines.FirstOrDefault(l => !l.IsBundle && l.ProductId == productId);
- var quantityNewlyAdded = linesNewlyAdded != null ? linesNewlyAdded.Quantity : 0;
- return quantityPreviouslyAdded + quantityNewlyAdded;
- }
- public bool MultipleAccountsIncluded(int productId, int bundleId)
- {
- return AccountsIncluded(productId, bundleId) > 1;
- }
- public int AccountsIncluded(int productId)
- {
- return AccountsIncluded(productId, CurrentBundle.Id);
- }
- public int AccountsIncluded(int productId, int bundleId)
- {
- return Bundles.First(b => b.Id == bundleId).BundleProducts.First(p => p.Product.Id == productId).NumberIncluded;
- }
- public int AccountsAvailable(int productId)
- {
- var currentOnAccount = SelectedAccount.AccountProducts.Where(a => a.Product.Id == productId).Sum(p => p.Quantity);
- var newlyAdded = OrderModel.OrderQuantity(productId);
- return currentOnAccount + newlyAdded;
- }
- public bool IsValidBundle(int bundleId)
- {
- return Bundles.Any(b => b.Id == bundleId);
- }
- public int InviteUser(string name, string surname, string existingEmail, string baseUrl, string emailAlias, string domain)
- {
- SmartaUser user;
- using (_userSystemPasswordRepository.DbContext.BeginTransaction())
- {
- try
- {
- var userToken = Guid.NewGuid();
- var pin = new PasswordGenerator().GeneratePin();
- var acc = _accountRepository.Get(_selectedAccountId);
- var dom = domain ?? UniqueDomainName;
- // Send activation email containing link to user
- CreateInvitationEmail(name, surname, existingEmail, userToken, baseUrl, emailAlias, dom, pin);
- user = CreateUser(name, surname, existingEmail, userToken, acc, pin);
- // Add user to system to the created user's selected account and Create username/password for their email account
- var login = CreateUserSystemLogin(user, acc, existingEmail, dom, emailAlias);
- // TODO : This needs to be done on the Join - so when the user actually logs on. Other accounts should also be created then too
- // if (!CreateEmailAccount(name, surname, login.Username, login.Password, emailAlias, domain ?? UniqueDomainName))
- // throw new ApiException("Unable to create email account", "Order");
- // Set password for user to access SBB
- _userSystemPasswordRepository.DbContext.CommitTransaction();
- }
- catch
- {
- _userSystemPasswordRepository.DbContext.RollbackTransaction();
- throw;
- }
- }
- return user.Id;
- }
- public bool SaveUserAccess(UserAccess userAccess, int userId)
- {
- var acc = _accountRepository.Get(_selectedAccountId);
- var usr = _userRepository.Get(userId);
- bool cancelEmailAccount = false;
- IEnumerable<SmartaUserAccountSystem> removed;
- // Delete those that have been removed first
- if (userAccess.HasSystemRoles)
- removed = UserPermissions.SelectedUserSystems.Where(u => !userAccess.SystemRoles.Any(s => s.SystemId == u.System.Id) || userAccess.SystemRoles.Any(s => s.SystemId == u.System.Id && s.RoleId != u.SystemRoleId));
- else
- removed = SelectedUserSystems;
- if (removed != null && removed.Count() > 0)
- {
- foreach (var system in removed)
- {
- if (system.System.Id == (int)SmartaSystem.Email)
- cancelEmailAccount = true;
- _userAccountSystemRepository.Delete(system);
- _userAccountSystemRepository.DbContext.CommitChanges();
- }
- }
- if (userAccess.HasSystemRoles)
- {
- foreach (var system in userAccess.SystemRoles)
- {
- // Do we need to add this one or is it already there with the same role if appropriate?
- if (UserPermissions.SelectedUserSystems.Any(u => u.System.Id == system.SystemId && u.SystemRoleId == system.RoleId))
- continue;
- var sys = _systemRepository.Get(system.SystemId);
- var suas = new SmartaUserAccountSystem(acc, sys);
- suas.SmartaUser = usr;
- suas.SystemRoleId = system.RoleId;
- _userAccountSystemRepository.SaveOrUpdate(suas);
- _userAccountSystemRepository.DbContext.CommitChanges();
- }
- }
- // Refresh the data for the next screen
- _userSystems = _userAccountSystemRepository.GetByAccount(_selectedAccountId);
- if (cancelEmailAccount)
- CancelEmailAccount(SelectedUser);
- return userAccess.HasSystemRoles && userAccess.SystemRoles.Any(s => s.SystemId == (int)SmartaSystem.Email) && !_userSystems.Where(s => s.SmartaUser.Id == SelectedUser.Id).Any(s => s.System.Id == (int)SmartaSystem.Email);
- }
- public void Upgrade(int bundleId)
- {
- // Cancel previous bundle order line item
- OrderModel.AddOrder(Bundles.First(b => b.Id == bundleId));
- }
- // TODO : If downgrading email accounts from, say, 6 to 4, and all accounts have been assigned (or in this instance there aren't 2 accounts unassigned) then we need to make the user choose whose account to cancel. Supply with list of email address (and details) and let them choose from there
- public void Downgrade(int bundleId)
- {
- // Cancel previous bundle order line item
- OrderModel.AddOrder(Bundles.First(b => b.Id == bundleId));
- }
- public void ProcessAccountCancellation(int SelectedAccountId)
- {
- // TODO : Complete account cancellation process
- }
- public bool CancellationChargeRequired(int selectedAccountId)
- {
- // TODO : This time should be put into a configurable component somewhere. 6 months is hard coded - not good!!!
- return _user.Accounts.First(a => a.Id == selectedAccountId).CreatedAt > new DateTime(DateTime.Now.Subtract(new DateTime(0, 6, 0)).Ticks);
- }
- public SmartaUser GetUser(int id, int accountId)
- {
- _user = _userRepository.Get(id);
- _selectedAccountId = accountId;
- return _user;
- }
- public void GetUserDetailsAndPermissions(int id)
- {
- //TODO: UI Caters for one Address Database caters for multiple what is required here?
- if (id != 0)
- {
- UserDetails.Address = _addressRepository.GetByUserAccount(id, _selectedAccountId).First();
- UserDetails.User = _userRepository.Get(id);
- UserPermissions = new UserPermissions(Systems, _userSystems, id, HasEmailAccountsRemaining);
- }
- else
- {
- UserDetails = new UserDetails();
- UserPermissions = new UserPermissions(Systems, HasEmailAccountsRemaining);
- }
- }
- public List<ValidationError> ValidateAddress(Address address)
- {
- var errors = new List<ValidationError>();
- if (String.IsNullOrEmpty(address.AddressName) && String.IsNullOrEmpty(address.Number))
- errors.Add(new ValidationError("AddressName", "Please enter a housename or number"));
- return errors;
- }
- public SmartaUser SaveUser(SmartaUser user, Address address)
- {
- using (_userRepository.DbContext.BeginTransaction())
- {
- user.Pin = new PasswordGenerator().Generate().Substring(0, 5);
- user.Token = Guid.NewGuid();
- user.Password = PasswordEncryption.Encrypt(new PasswordGenerator().Generate());
- if (user.UserStatus == null)
- user.UserStatus = new UserStatus((int)Enums.UserStatus.Active);
- CreateUser(user);
- address.AccountId = _selectedAccountId;
- address.CreatedBy = _user.Id;
- address.SmartaUserId = user.Id;
- address.ModifiedBy = _user.Id;
- _addressRepository.SaveOrUpdate(address);
- _addressRepository.DbContext.CommitChanges();
- _userRepository.DbContext.CommitTransaction();
- }
- return user;
- }
- public SmartaUser SaveUser(SmartaUser user, Address address, UserAccess userAccess)
- {
- //Check If in Edit mode
- if (UserDetails.User.Id != 0)
- {
- SmartaUser currentSmarterUser = _userRepository.Get(UserDetails.User.Id);
- Address currentAddress = _addressRepository.GetByUserAccount(UserDetails.User.Id, SelectedAccount.Id).First();
- currentSmarterUser.Forename = user.Forename;
- currentSmarterUser.Surname = user.Surname;
- currentSmarterUser.EmailAddress = user.EmailAddress;
- currentAddress.Number = address.Number;
- currentAddress.AddressName = address.AddressName;
- currentAddress.AddressLine1 = address.AddressLine1;
- currentAddress.AddressLine2 = address.AddressLine2;
- currentAddress.AddressLine3 = address.AddressLine3;
- currentAddress.Town = address.Town;
- currentAddress.County = address.County;
- currentAddress.Postcode = address.Postcode;
- currentAddress.Country = address.Country;
- user = currentSmarterUser;
- address = currentAddress;
- }
- else
- {
- user.Pin = new PasswordGenerator().Generate().Substring(0, 5);
- user.Token = Guid.NewGuid();
- user.Password = PasswordEncryption.Encrypt(new PasswordGenerator().Generate());
- }
- using (_userRepository.DbContext.BeginTransaction())
- {
- if (user.UserStatus == null)
- user.UserStatus = new UserStatus((int)Enums.UserStatus.Active);
- CreateUser(user);
- address.AccountId = _selectedAccountId;
- address.CreatedBy = _user.Id;
- address.SmartaUserId = user.Id;
- address.ModifiedBy = _user.Id;
- _addressRepository.SaveOrUpdate(address);
- _addressRepository.DbContext.CommitChanges();
- //Save User Access Here
- GetUser(user.Id);
- SaveUserAccess(userAccess, user.Id);
- _userRepository.DbContext.CommitTransaction();
- }
- return user;
- }
- public List<ValidationError> Validate(string name, string surname, string existingEmail, string emailAlias, string selectDomainName)
- {
- var errors = new List<ValidationError>();
- if (string.IsNullOrEmpty(name))
- errors.Add(new ValidationError("Name", "Name is required"));
- if (string.IsNullOrEmpty(surname))
- errors.Add(new ValidationError("Surname", "Surname is required"));
- if (string.IsNullOrEmpty(existingEmail))
- errors.Add(new ValidationError("ExistingEmail", "Existing email is required"));
- if (string.IsNullOrEmpty(emailAlias))
- errors.Add(new ValidationError("EmailAlias", "Email alias is required"));
- if (AllowDomainSelection && string.IsNullOrEmpty(selectDomainName))
- errors.Add(new ValidationError("SelectDomainName", "Please select domain to use"));
- if (!EmailAddressAvailable(emailAlias, selectDomainName))
- errors.Add(new ValidationError("EmailAlias", "That alias has already been taken. Please enter another"));
- return errors;
- }
- public List<ValidationError> ValidateEmailAccount(string domain, string emailAlias)
- {
- var errors = new List<ValidationError>();
- if (string.IsNullOrEmpty(emailAlias))
- errors.Add(new ValidationError("EmailAlias", "Alias is required"));
- if (!EmailAddressAvailable(emailAlias, domain ?? UniqueDomainName))
- errors.Add(new ValidationError("EmailAlias", "That alias has already been taken. Please enter another"));
- return errors;
- }
- public void CreateEmailAccount(string domain, string emailAlias)
- {
- // Check to see whether the user is currently a user on the email system. If they are then we should add the domain and alias to the account rather than performing an order and creating the user
- var login = _userSystemPasswordRepository.GetByUserAndProduct(_user.Id, _selectedAccountId, SmartaSystem.Email);
- if (login == null)
- {
- login = CreateUserSystemLogin(_user, SelectedAccount, _user.EmailAddress, domain, emailAlias);
- CreateEmailAccount(_user.Forename, _user.Surname, login.Username, login.Password, emailAlias, domain);
- // Do we need to update the MX record here
- if (SelectedAccount.Domains.First(d => d.FullName == domain).DomainType.Id != (int)Enums.DomainType.Smarta)
- UpdateMxRecordForDomain(domain);
- }
- else
- {
- // Add domain to the login and create alias
- if (AddDomain(domain, login))
- {
- if (AddAlias(string.Format("{0}@{1}", emailAlias, domain), login))
- {
- // Update domain to set EmailSetup = true
- var account = _accountRepository.Get(_selectedAccountId);
- account.Domains.First(d => d.FullName == domain).EmailSetup = true;
- _accountRepository.SaveOrUpdate(account);
- _accountRepository.DbContext.CommitChanges();
- }
- // Update the MX Record
- if (!UpdateMxRecordForDomain(domain))
- {
- // TODO : Log unable to update MX record for domain. Should we send an email here or just log?
- Logger.Log.Warning(string.Format("Unable to update MX record for domain : {0}", domain));
- }
- }
- }
- }
- public string AddOnCost(int productId, decimal price)
- {
- int qty = 0;
- var order = SelectedAccount.Orders.Where(x => x.HasOrderLines).Where(o => o.OrderLines.Any(i => !i.Cancelled && !i.IsBundle && i.ProductId == productId));
- if (order != null && order.Count() > 0)
- {
- qty = order.Where(o => o.HasOrderLines).ToList().Sum(o => o.OrderLines.Where(l => l.ProductId == productId).Sum(ol => ol.Quantity));
- //qty = order.OrderLines.Where(o => !o.IsBundle && !o.Cancelled && o.ProductId == productId).Sum(p => p.Quantity);
- }
- // Add on current order as well
- if (OrderModel.Order != null && OrderModel.Order.HasOrderLines)
- {
- var orderline = OrderModel.Order.OrderLines.FirstOrDefault(p => !p.IsBundle && p.Product.Id == productId);
- if (orderline != null)
- qty += orderline.Quantity;
- }
- return (qty * price).ToString("#0.00");
- }
- public int AccountsUsed(int systemId)
- {
- return _userSystems.Count(u => u.System.Id == systemId);
- }
- #endregion
- #region Private methods
- private void CancelAccountLevelAccess()
- {
- var accounts = _accountSystemRepository.GetByAccount(_selectedAccountId);
- foreach (var account in accounts)
- {
- switch (account.SystemId)
- {
- case Enums.SmartaSystem.Email:
- CancelEmailAccount(account.Username);
- break;
- case Enums.SmartaSystem.Website:
- // Should we cancel each website within here or above? I think maybe above. The access to the Website builder is per account rather than per user so this shouldn't come up here but be dealt with separately
- CancelWebsite(account.Username);
- break;
- case Enums.SmartaSystem.Accounts:
- // Should we cancel within here or above? I think maybe above. The access to the Accounts is per account rather than per user so this shouldn't come up here but be dealt with separately
- CancelAccounts(account.Username, account.Password);
- break;
- case Enums.SmartaSystem.BusinessPlan:
- // Should we cancel within here or above? I think maybe above. How is the access to the business plan done? Do we create a single user on an account basis and have all other users that have this access use this login credentials
- CancelBusinessPlan(account.Username, account.Password);
- break;
- case Enums.SmartaSystem.LegalDocuments:
- CancelLegal(account.Username, account.Password);
- break;
- case Enums.SmartaSystem.WorldPay:
- // TODO : Do we need to cancel World Pay
- break;
- case Enums.SmartaSystem.Domain:
- // Need to cancel all domains relating to the account so done below
- break;
- }
- }
- }
- private void CancelUserLevelAccess()
- {
- var accounts = _userSystemPasswordRepository.GetByAccount(_selectedAccountId);
- foreach (var account in accounts)
- {
- switch (account.SystemId)
- {
- case Enums.SmartaSystem.Email:
- CancelEmailAccount(account.Username);
- break;
- case Enums.SmartaSystem.Website:
- // Should we cancel each website within here or above? I think maybe above. The access to the Website builder is per account rather than per user so this shouldn't come up here but be dealt with separately
- CancelWebsite(account.Username);
- break;
- case Enums.SmartaSystem.Accounts:
- // Should we cancel within here or above? I think maybe above. The access to the Accounts is per account rather than per user so this shouldn't come up here but be dealt with separately
- CancelAccounts(account.Username, account.Password);
- break;
- case Enums.SmartaSystem.BusinessPlan:
- // Should we cancel within here or above? I think maybe above. How is the access to the business plan done? Do we create a single user on an account basis and have all other users that have this access use this login credentials
- CancelBusinessPlan(account.Username, account.Password);
- break;
- case Enums.SmartaSystem.LegalDocuments:
- CancelLegal(account.Username, account.Password);
- break;
- case Enums.SmartaSystem.WorldPay:
- // TODO : Do we need to cancel World Pay
- break;
- case Enums.SmartaSystem.Domain:
- // Need to cancel all domains relating to the account so done below
- break;
- }
- }
- }
- private void CreateCancellationEmail()
- {
- EmailContent emailContent = new EmailContent();
- emailContent.Name = string.Format("{0} {1}", _user.Forename, _user.Surname);
- Email mail = new Email();
- mail.Body = EmailBody.Create(Path.Combine(SmartaBusinessBuilderSettings.Settings.EmailTemplateFoilder, "AccountCancelled.xslt"), emailContent);
- mail.FromAddress = SmartaBusinessBuilderSettings.Settings.EmailFromAddress;
- mail.SubjectId = (int)EmailSubjectType.AccountCancelled;
- mail.ToAddress = _user.EmailAddress;
- _emailRepository.SaveOrUpdate(mail);
- _emailRepository.DbContext.CommitChanges();
- }
- private void GetData()
- {
- // TODO : Now, this currently displays ALL systems irrespective of whether the user has included the add-ons. What should happen here? This is a UI Decision as I can see 2 options and both are valid : 1-Only display those systems available to the user;2-Display all systems but have an N/A next to them. This allows the user to see what is available if they select the add-on. It enables the user to see the option and maybe be tempted to upgrade to include that...
- Systems = _systemRepository.GetAll();
- Users = _accountRepository.Get(_selectedAccountId).Users;
- _userSystems = _userAccountSystemRepository.GetByAccount(_selectedAccountId);
- }
- private bool AddDomain(string domain, UserSystemPassword login)
- {
- EmailRequest request = new EmailRequest();
- request.Domain = domain;
- request.User = login.Username;
- return EmailGateway.AddDomain(EmailAdminValueCollection, request).IsSuccessful;
- }
- private bool AddAlias(string alias, UserSystemPassword login)
- {
- EmailRequest request = new EmailRequest();
- request.Alias = alias;
- request.User = login.Username;
- return EmailGateway.AddAlias(EmailAdminValueCollection, request).IsSuccessful;
- }
- private IEmail EmailGateway
- {
- get
- {
- if (_emailGateway == null)
- _emailGateway = ServiceLocator.Current.GetInstance<IEmail>("IEmail");
- return _emailGateway;
- }
- }
- private AdminLoginCollection EmailAdminValueCollection
- {
- get
- {
- return new AdminLoginCollection(AdminValueCollection.Where(a => a.AdminLoginTypeId == AdminLoginType.Email).ToList());
- }
- }
- private IList<AdminLoginValue> AdminValueCollection
- {
- get
- {
- if (_adminValues == null)
- _adminValues = _adminLoginRepository.GetAll();
- return _adminValues;
- }
- }
- private AdminLoginCollection DomainAdminValueCollection
- {
- get
- {
- return new AdminLoginCollection(AdminValueCollection.Where(a => a.AdminLoginTypeId == AdminLoginType.DomainReseller).ToList());
- }
- }
- private bool UpdateMxRecordForDomain(string domain)
- {
- DomainRequest request = new DomainRequest();
- request.Domain = domain;
- var response = _domain.ParseDomain(request, DomainAdminValueCollection);
- request.Tld = response.Tld;
- request.Sld = response.Sld;
- return _domain.SetMxAddress(request, DomainAdminValueCollection).IsSuccessful;
- }
- private UserSystemPassword CreateUserSystemLogin(SmartaUser user, Account acc, string existingEmail, string domain, string alias)
- {
- var account = _accountRepository.Get(_selectedAccountId);
- user = _userRepository.Get(user.Id);
- if (account.Domains.Count == 1)
- account.Domains.First().EmailSetup = true;
- else
- account.Domains.First(d => d.FullName == domain).EmailSetup = true;
- account.AccountProducts.Where(ap => ap.Product.System.Id == (int)SmartaSystem.Email).ToList().ForEach(a => a.ProductStatus = new SystemStatus((int)ProductStatus.Active));
- string password = new PasswordGenerator().Generate();
- UserSystemPassword pwd = new UserSystemPassword();
- pwd.EncryptedPassword = PasswordEncryption.DEncrypt(password);
- pwd.SmartaUser = user;
- pwd.SystemId = SmartaSystem.Email;
- pwd.Username = string.Format("{0}@{1}", alias, domain);
- pwd.Account = account;
- _userSystemPasswordRepository.SaveOrUpdate(pwd);
- _userSystemPasswordRepository.DbContext.CommitChanges();
- return pwd;
- }
- private bool EmailAddressAvailable(string emailAlias, string domainName)
- {
- var response = EmailGateway.CheckAlias(EmailAdminValueCollection, new EmailRequest() { Alias = emailAlias, Domain = domainName });
- return response.IsSuccessful;
- }
- private SmartaUser CreateUser(SmartaUser user)
- {
- var acc = _accountRepository.Get(_selectedAccountId);
- // Products assigned to the Email System type available to the current logged on user. These need to be added to the new user
- var emailProducts = SelectedAccount.AccountProducts.Where(p => p.Product.System.Id == (int)SmartaSystem.Email).Select(ap => ap.Product.System);
- if (UserDetails.User.Id == 0)
- { user.AddAccount(acc); }
- UserAccountSystemCollection col = new UserAccountSystemCollection();
- col.AddSystem(acc, emailProducts);
- _userRepository.SaveOrUpdate(user);
- _userRepository.DbContext.CommitChanges();
- col.SmartaUser = user;
- var systems = col.SmartaUserAccountProducts.Distinct((lhs, rhs) => lhs.System.Id == rhs.System.Id, hash => hash.System.Id.GetHashCode());
- foreach (var suap in systems)
- {
- _userAccountSystemRepository.SaveOrUpdate(suap);
- _userAccountSystemRepository.DbContext.CommitChanges();
- }
- return user;
- }
- private bool CreateEmailAccount(string name, string surname, string username, string password, string emailAlias, string domain)
- {
- EmailRequest request = new EmailRequest();
- request.Firstname = name;
- request.Lastname = surname;
- request.User = username;
- request.EmailAddress = _user.EmailAddress;
- request.Password = password;
- request.AddAlias(emailAlias, domain);
- request.Domain = domain;
- var response = EmailGateway.Order(EmailAdminValueCollection, request);
- return response.IsSuccessful;
- }
- private void CancelEmailAccount(SmartaUser SelectedUser)
- {
- // Get the account logon for this user
- var userLogon = _userSystemPasswordRepository.GetByUserAndProduct(SelectedUser.Id, _selectedAccountId, SmartaSystem.Email);
- CancelEmailAccount(userLogon.Username);
- }
- private void CancelDomains()
- {
- // Only need to cancel those domains bought through SBB. If previoulsy owned then the user should have the details they require. If Smarta, then the domain is owned by smarta
- var domains = SelectedAccount.Domains.Where(d => d.DomainType.Id < (int)Enums.DomainType.Owned);
- foreach (var domain in domains)
- {
- var request = new DomainRequest(domain.Name, domain.DomainType.Name);
- var response = _domain.CancelDomain(request, DomainAdminValueCollection);
- StoreProviderOutput("Cancel", SmartaSystem.Domain, response.ResponseText);
- }
- }
- private void CancelBusinessPlan(string username, string password)
- {
- // TODO : Control the cancellation of the Business Plan if required
- BusinessPlanRequest request = new BusinessPlanRequest();
- request.Username = username;
- request.Password = password;
- var response = _businessPlan.CancelAccount(BusinessPlanAdminValueCollection, request);
- StoreProviderOutput("Cancel", SmartaSystem.BusinessPlan, response.ResponseText);
- }
- private void CancelLegal(string username, string password)
- {
- LegalDocumentRequest request = new LegalDocumentRequest();
- request.ExternalUserId = username;
- request.ExternalUserPassword = password;
- var response = Legal.CancelAccount(LegalAdminValueCollection, request);
- StoreProviderOutput("Cancel", SmartaSystem.LegalDocuments, response.ResponseText);
- }
- private void CancelAccounts(string username, string password)
- {
- // TODO : Cancel Accounts package
- AccountRequest request = new AccountRequest();
- request.Username = username;
- request.Password = password;
- var response = _accounts.CancelAccount(AccountsAdminValueCollection, request);
- StoreProviderOutput("Cancel", SmartaSystem.Accounts, response.ResponseText);
- }
- private void CancelWebsite(string username)
- {
- WebsiteRequest request = new WebsiteRequest();
- request.Username = username;
- // Need to get the user id first to be able to cancel the account
- var response = WebsiteBuilder.GetAccountInfo(WebsiteAdminValueCollection, request);
- request.UserId = response.UserId;
- response = WebsiteBuilder.CancelAccount(WebsiteAdminValueCollection, request);
- StoreProviderOutput("Cancel", SmartaSystem.Website, response.ResponseText);
- }
- private void CancelEmailAccount(string username)
- {
- EmailRequest request = new EmailRequest();
- request.User = username;
- var response = EmailGateway.Terminate(EmailAdminValueCollection, request);
- StoreProviderOutput("Cancel", SmartaSystem.Email, response.ResponseText);
- }
- private void StoreProviderOutput(string apiCall, SmartaSystem smartaSystem, string response)
- {
- ProviderOutput output = new ProviderOutput();
- output.AccountId = _selectedAccountId;
- output.ApiCall = apiCall;
- output.SystemId = (int)smartaSystem;
- output.ProviderResponse = response;
- _outputRepository.SaveOrUpdate(output);
- _outputRepository.DbContext.CommitChanges();
- }
- private void CreateInvitationEmail(string name, string surname, string existingEmail, Guid userToken, string baseUrl, string emailAlias, string domain, string pin)
- {
- EmailContent emailContent = new EmailContent();
- emailContent.Name = string.Format("{0} {1}", name, surname);
- emailContent.Url = string.Format("{0}/Admin/Join/{1}", baseUrl, userToken.ToString());
- emailContent.Invitor = string.Format("{0} {1}", _user.Forename, _user.Surname);
- emailContent.EmailAddress = string.Format("{0}@{1}", emailAlias, domain);
- emailContent.Pin = pin;
- Email mail = new Email();
- mail.Body = EmailBody.Create(Path.Combine(SmartaBusinessBuilderSettings.Settings.EmailTemplateFoilder, "InvitationToEmailAccount.xslt"), emailContent);
- mail.FromAddress = SmartaBusinessBuilderSettings.Settings.EmailFromAddress;
- mail.SubjectId = (int)EmailSubjectType.Invite;
- mail.ToAddress = existingEmail;
- _emailRepository.SaveOrUpdate(mail);
- _emailRepository.DbContext.CommitChanges();
- }
- private SmartaUser CreateUser(string name, string surname, string existingEmail, Guid userToken, Account acc, string pin)
- {
- SmartaUser user = _userRepository.GetByEmailAddress(existingEmail);
- if (user == null)
- {
- user = new SmartaUser();
- user.Forename = name;
- user.Surname = surname;
- // This can be overwritten shortly, but create a password for now to prevent anybody being able to login with this userid
- user.Password = PasswordEncryption.Encrypt(new PasswordGenerator().Generate());
- user.EmailAddress = existingEmail;
- user.UserStatus = new UserStatus((int)Enums.UserStatus.Invited);
- }
- user.Token = userToken;
- user.Pin = pin;
- return CreateUser(user);
- }
- private decimal GetAdditionalLicenseCost(bool monthlyCharge)
- {
- decimal price = SelectedAccount.Orders.Where(l => l.HasOrderLines).Sum(m => m.OrderLines.Where(n => !n.Cancelled && !n.IsBundle && CurrentBundle.IncludedProducts.Any(p => p.Id == n.ProductId) && (n.Product.IsMonthlyCharge == monthlyCharge)).Sum(q => q.Price * q.Quantity));
- // Add on current order as well
- if (OrderModel.Order != null && OrderModel.Order.HasOrderLines)
- {
- var orderlines = OrderModel.Order.OrderLines.Where(p => !p.IsBundle);
- if (orderlines != null && orderlines.Count() > 0)
- price += orderlines.Where(p => (p.Product.IsMonthlyCharge == monthlyCharge) && CurrentBundle.IncludedProducts.Any(pr => pr.Id == p.ProductId)).Sum(l => l.Price * l.Quantity);
- }
- return price > 0 ? price : 0;
- }
- private decimal GetTotalAdditionalLicenseCost()
- {
- decimal price = 0;
- if (OrderModel.Order != null && OrderModel.Order.HasOrderLines)
- {
- var orderlines = OrderModel.Order.OrderLines.Where(p => !p.IsBundle && (p.Quantity > 0 || p.Product.IsMonthlyCharge));
- if (orderlines != null && orderlines.Count() > 0)
- price += orderlines.Where(p => CurrentBundle.IncludedProducts.Any(pr => pr.Id == p.ProductId)).Sum(l => l.Price * l.Quantity);
- }
- return price > 0 ? price : 0;
- }
- private decimal GetAdditionalAddOnCost(bool monthlyCharge)
- {
- decimal price = SelectedAccount.Orders.Where(l => l.HasOrderLines).Sum(m => m.OrderLines.Where(n => !n.Cancelled && !n.IsBundle && CurrentBundle.AddOns.Any(p => p.Id == n.ProductId) && (n.Product.IsMonthlyCharge == monthlyCharge)).Sum(q => q.Price * q.Quantity));
- // Add on current order as well
- if (OrderModel.Order != null && OrderModel.Order.HasOrderLines)
- {
- var orderlines = OrderModel.Order.OrderLines.Where(p => !p.IsBundle);
- if (orderlines != null && orderlines.Count() > 0)
- price += orderlines.Where(p => (p.Product.IsMonthlyCharge == monthlyCharge) && CurrentBundle.AddOns.Any(pr => pr.Id == p.ProductId)).Sum(l => l.Price * l.Quantity);
- }
- return price > 0 ? price : 0;
- }
- private decimal GetTotalAdditionalAddOnCost()
- {
- decimal price = 0;
- if (OrderModel.Order != null && OrderModel.Order.HasOrderLines)
- {
- var orderlines = OrderModel.Order.OrderLines.Where(p => !p.IsBundle && (p.Quantity > 0 || p.Product.IsMonthlyCharge));
- if (orderlines != null && orderlines.Count() > 0)
- price += orderlines.Where(p => CurrentBundle.AddOns.Any(pr => pr.Id == p.ProductId)).Sum(l => l.Price * l.Quantity);
- }
- return price > 0 ? price : 0;
- }
- #endregion
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement