예제 #1
0
        public ActionResult ReadAjaxServiceComponentsGrid([DataSourceRequest] DataSourceRequest request, int?serviceFunctionId)
        {
            DataSourceResult result = null;

            try
            {
                if (_appUserContext.Current?.CurrentCustomer != null && _appUserContext.Current.CurrentCustomer.Id > 0)
                {
                    var all = new List <ServiceComponentViewModel>();

                    // Get all the level 1 results. These will have the level 2's inside so we don't have to do another query.
                    var parentComponentListItems = _serviceComponentService
                                                   .GetByCustomerWithHierarchy(_appUserContext.Current.CurrentCustomer.Id)
                                                   .Where(x => x.ServiceComponent.ComponentLevel == (int)ServiceComponentLevel.Level1 &&
                                                          (!serviceFunctionId.HasValue || x.ServiceFunctionId == serviceFunctionId.Value))
                                                   .OrderBy(o => o.ServiceComponent.DiagramOrder).ThenBy(o => o.ServiceComponent.ComponentName)
                                                   .ToList();

                    // Add all level 1's to the list, but insert the level 2's so they will appear underneath.
                    foreach (var parentServiceComponent in parentComponentListItems)
                    {
                        all.Add(Mapper.Map <ServiceComponentViewModel>(parentServiceComponent));

                        if (parentServiceComponent.ServiceComponent.ChildServiceComponents == null ||
                            !parentServiceComponent.ServiceComponent.ChildServiceComponents.Any())
                        {
                            continue;
                        }

                        // Now overwrite with the specific level 2 info.
                        foreach (var childComponent in parentServiceComponent.ServiceComponent.ChildServiceComponents.OrderBy(o => o.DiagramOrder).ThenBy(o => o.ComponentName))
                        {
                            // We repeat the above for the level 2 as the main parent info will be the same as the level 1.
                            var child = Mapper.Map <ServiceComponentViewModel>(parentServiceComponent);
                            var childServiceComponent = Mapper.Map(childComponent, child);
                            all.Add(childServiceComponent);
                        }
                    }

                    // Return to the grid.
                    result = all.ToDataSourceResult(request);
                }
            }
            catch (Exception ex)
            {
                _contextManager.ResponseManager.StatusCode = 500;
                _contextManager.ResponseManager.AppendHeader(ModelStateErrorNames.ErrorMessage, ex.Message);
            }

            return(Json(result));
        }
        public void ServiceComponentService_GetByCustomerWithHierarchy_CustomerIdSupplied_ReturnsOnlyThoseComponentsForCustomer()
        {
            var results = _target
                          .GetByCustomerWithHierarchy(CustomerId)
                          .ToList();

            Assert.IsFalse(results.Any(x => x.ServiceComponent.ServiceFunction.ServiceDomain.ServiceDesk.CustomerId != CustomerId));
        }
 protected List <SelectListItem> GetServiceComponentHierarchy(int?serviceFunctionIdFilter)
 {
     return(_serviceComponentService
            .GetByCustomerWithHierarchy(_appUserContext.Current.CurrentCustomer.Id)
            .Where(x => x.ServiceComponent.ComponentLevel == (int)ServiceComponentLevel.Level1 &&
                   x.ServiceComponent.Resolver == null &&
                   (!serviceFunctionIdFilter.HasValue || x.ServiceFunctionId == serviceFunctionIdFilter.Value))
            .Select(x => new SelectListItem
     {
         Text = string.Concat(x.ServiceDeskName,
                              UnicodeCharacters.DoubleArrowRight,
                              x.ServiceDomainName,
                              UnicodeCharacters.DoubleArrowRight,
                              x.ServiceFunctionName,
                              UnicodeCharacters.DoubleArrowRight,
                              x.ServiceComponent.ComponentName),
         Value = x.ServiceComponent.Id.ToString()
     })
            .ToList());
 }