示例#1
0
        public Subscription[] GetByIds(string[] subscriptionIds, string responseGroup = null)
        {
            var retVal = new List <Subscription>();
            var subscriptionResponseGroup = EnumUtility.SafeParse(responseGroup, SubscriptionResponseGroup.Full);

            using (var repository = _subscriptionRepositoryFactory())
            {
                repository.DisableChangesTracking();

                var subscriptionEntities = repository.GetSubscriptionsByIds(subscriptionIds, responseGroup);
                foreach (var subscriptionEntity in subscriptionEntities)
                {
                    var subscription = AbstractTypeFactory <Subscription> .TryCreateInstance();

                    if (subscription != null)
                    {
                        subscription = subscriptionEntity.ToModel(subscription) as Subscription;
                        if (subscriptionResponseGroup.HasFlag(SubscriptionResponseGroup.WithChangeLog))
                        {
                            //Load change log by separate request
                            _changeLogService.LoadChangeLogs(subscription);
                        }
                        retVal.Add(subscription);
                    }
                }
            }

            CustomerOrder[] orderPrototypes    = null;
            CustomerOrder[] subscriptionOrders = null;

            if (subscriptionResponseGroup.HasFlag(SubscriptionResponseGroup.WithOrderPrototype))
            {
                orderPrototypes = _customerOrderService.GetByIds(retVal.Select(x => x.CustomerOrderPrototypeId).ToArray());
            }
            if (subscriptionResponseGroup.HasFlag(SubscriptionResponseGroup.WithRelatedOrders))
            {
                //Loads customer order prototypes and related orders for each subscription via order service
                var criteria = new CustomerOrderSearchCriteria
                {
                    SubscriptionIds = subscriptionIds
                };
                subscriptionOrders = _customerOrderSearchService.SearchCustomerOrders(criteria).Results.ToArray();
            }

            foreach (var subscription in retVal)
            {
                if (!orderPrototypes.IsNullOrEmpty())
                {
                    subscription.CustomerOrderPrototype = orderPrototypes.FirstOrDefault(x => x.Id == subscription.CustomerOrderPrototypeId);
                }
                if (!subscriptionOrders.IsNullOrEmpty())
                {
                    subscription.CustomerOrders    = subscriptionOrders.Where(x => x.SubscriptionId == subscription.Id).ToList();
                    subscription.CustomerOrdersIds = subscription.CustomerOrders.Select(x => x.Id).ToArray();
                }
            }

            return(retVal.ToArray());
        }
示例#2
0
        protected virtual async Task <ApplicationUserExtended> GetUserExtendedAsync(ApplicationUser applicationUser, UserDetails detailsLevel)
        {
            ApplicationUserExtended result = null;

            if (applicationUser != null)
            {
                result = await _cacheManager.GetAsync($"GetUserByName-{applicationUser.UserName}-{detailsLevel}", SecurityConstants.CacheRegion, async() =>
                {
                    ApplicationUserExtended retVal;
                    using (var repository = _platformRepository())
                    {
                        var user = await repository.GetAccountByNameAsync(applicationUser.UserName, detailsLevel);
                        retVal   = applicationUser.ToCoreModel(user, _permissionScopeService);
                        //Populate available permission scopes
                        if (retVal.Roles != null)
                        {
                            foreach (var permission in retVal.Roles.SelectMany(x => x.Permissions).Where(x => x != null))
                            {
                                permission.AvailableScopes = _permissionScopeService.GetAvailablePermissionScopes(permission.Id).ToList();
                            }
                        }

                        //Load log entities to account
                        if (detailsLevel.HasFlag(UserDetails.Full) || detailsLevel.HasFlag(UserDetails.Export))
                        {
                            _changeLogService.LoadChangeLogs(retVal);
                        }
                    }

                    var suppressForcingCredentialsChange = ConfigurationHelper.GetAppSettingsValue("VirtoCommerce:Security:SuppressForcingCredentialsChange", false);
                    if (!suppressForcingCredentialsChange)
                    {
                        //Setting the flags which indicates a necessity of security credentials change
                        retVal.PasswordExpired |= retVal.PasswordHash == Resources.Default.DefaultPasswordHash;
                        if (retVal.ApiAccounts != null)
                        {
                            foreach (var apiAccount in retVal.ApiAccounts)
                            {
                                apiAccount.SecretKeyExpired = apiAccount.SecretKey == Resources.Default.DefaultSecretKey;
                            }
                        }
                    }

                    if (detailsLevel != UserDetails.Export)
                    {
                        retVal.PasswordHash  = null;
                        retVal.SecurityStamp = null;
                    }

                    return(retVal);
                });
            }
            return(result);
        }
示例#3
0
 public IEnumerable <QuoteRequest> GetByIds(params string[] ids)
 {
     using (var repository = _repositoryFactory())
     {
         var retVal = repository.GetQuoteRequestByIds(ids).Select(x => x.ToCoreModel()).ToArray();
         foreach (var quote in retVal)
         {
             _dynamicPropertyService.LoadDynamicPropertyValues(quote);
             _changeLogService.LoadChangeLogs(quote);
             _eventPublisher.Publish(new QuoteRequestChangeEvent(EntryState.Unchanged, quote, quote));
         }
         return(retVal);
     }
 }
示例#4
0
        public IHttpActionResult GetOrderChanges(string id)
        {
            var result = new OperationLog[] { };
            var order  = _customerOrderService.GetByIds(new[] { id }).FirstOrDefault();

            if (order != null)
            {
                _changeLogService.LoadChangeLogs(order);
                //Load general change log for order
                result = order.GetFlatObjectsListWithInterface <IHasChangesHistory>()
                         .Distinct()
                         .SelectMany(x => x.OperationsLog)
                         .OrderBy(x => x.CreatedDate)
                         .Distinct().ToArray();
            }
            return(Ok(result));
        }
示例#5
0
        public async Task <ActionResult <OperationLog[]> > GetOrderChanges(string id)
        {
            var result = new OperationLog[] { };
            var order  = await _customerOrderService.GetByIdAsync(id);

            if (order != null)
            {
                _changeLogService.LoadChangeLogs(order);
                //Load general change log for order
                result = order.GetFlatObjectsListWithInterface <IHasChangesHistory>()
                         .Distinct()
                         .SelectMany(x => x.OperationsLog)
                         .OrderBy(x => x.CreatedDate)
                         .Distinct().ToArray();
            }
            return(Ok(result));
        }
示例#6
0
        public async Task <License[]> GetByIdsAsync(string[] ids)
        {
            License[] result;

            using (var repository = _licenseRepositoryFactory())
            {
                var arrayLicense = await repository.GetByIdsAsync(ids);

                result = arrayLicense
                         .Select(x =>
                {
                    var retVal = x.ToModel(AbstractTypeFactory <License> .TryCreateInstance());
                    //Load change log by separate request
                    _changeLogService.LoadChangeLogs(retVal);
                    return(retVal);
                })
                         .ToArray();
            }

            return(result);
        }
        protected virtual ApplicationUserExtended GetUserExtended(ApplicationUser applicationUser, UserDetails detailsLevel)
        {
            ApplicationUserExtended result = null;

            if (applicationUser != null)
            {
                result = _cacheManager.Get($"GetUserByName-{applicationUser.UserName}-{detailsLevel}", SecurityConstants.CacheRegion, () =>
                {
                    ApplicationUserExtended retVal;
                    using (var repository = _platformRepository())
                    {
                        var user = repository.GetAccountByName(applicationUser.UserName, detailsLevel);
                        retVal   = applicationUser.ToCoreModel(user, _permissionScopeService);
                        //Populate available permission scopes
                        if (retVal.Roles != null)
                        {
                            foreach (var permission in retVal.Roles.SelectMany(x => x.Permissions).Where(x => x != null))
                            {
                                permission.AvailableScopes = _permissionScopeService.GetAvailablePermissionScopes(permission.Id).ToList();
                            }
                        }

                        //Load log entities to account
                        if (detailsLevel.HasFlag(UserDetails.Full) || detailsLevel.HasFlag(UserDetails.Export))
                        {
                            _changeLogService.LoadChangeLogs(retVal);
                        }
                    }

                    if (detailsLevel != UserDetails.Export)
                    {
                        retVal.PasswordHash  = null;
                        retVal.SecurityStamp = null;
                    }

                    return(retVal);
                });
            }
            return(result);
        }