/// <summary> /// Return view to update a package /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult UpdatePackage(int id) { PackageModel model = new PackageModel(); try //try and get a package { var package = (ServiceRequestPackageDto)_portfolioService.GetServiceRequestPackage(UserId, id); model.Name = package.Name; model.Action = package.Action; if (package.ServiceOptionCategoryTags != null) { model.SelectedCategories = from a in package.ServiceOptionCategoryTags select a.ServiceOptionCategoryId; //fill selections if (package.ServiceOptionCategoryTags.FirstOrDefault(x => x.Order == 1) != null) //figure out primary { model.PrimaryIsService = false; model.PrimaryId = (from c in package.ServiceOptionCategoryTags where c.Order == 1 select c.ServiceOptionCategoryId).First(); } } if (package.ServiceTags != null) { model.SelectedServices = from a in package.ServiceTags select a.ServiceId; //fill sections if (package.ServiceTags.FirstOrDefault(x => x.Order == 1) != null) //figure out primary if it is in here { model.PrimaryIsService = true; model.PrimaryId = (from c in package.ServiceTags where c.Order == 1 select c.ServiceId).First(); } } } catch (Exception exception) { TempData["MessageType"] = WebMessageType.Failure; TempData["Message"] = $"Failed to retrieve service package, error: {exception.Message}"; } try //build services list to select from { var services = _catalogController.RequestBusinessCatalog(UserId).ToList(); //build list services.AddRange(_catalogController.RequestSupportCatalog(UserId)); model.Services = services; } catch (Exception exception) { TempData["MessageType"] = WebMessageType.Failure; TempData["Message"] = $"failed to obtain services, error: {exception.Message}"; } return(View(model)); }
public List <ICatalogPublishable> Search(Helpers.Enums.ServiceCatalog catalog, string searchString, int userId) { List <ICatalogPublishable> searchresults = new List <ICatalogPublishable>(); //start the container for catalogables if (catalog == Helpers.Enums.ServiceCatalog.Both || catalog == Helpers.Enums.ServiceCatalog.Business) //add things from the business catalog { var services = (from s in _catalogController.RequestBusinessCatalog(userId) select s).ToList(); searchresults.AddRange(from s in services where searchString != null && s.Name.ToLower().Contains(searchString) select(ICatalogPublishable) s); foreach (var service in services) { //searchresults.AddRange(from o in service.ServiceOptions where searchString != null && o.Name.ToLower().Contains(searchString) select (ICatalogPublishable)o); searchresults.AddRange(from c in service.ServiceOptionCategories where searchString != null && c.Name.ToLower().Contains(searchString) select(ICatalogPublishable) c); } } if (catalog == Helpers.Enums.ServiceCatalog.Both || catalog == Helpers.Enums.ServiceCatalog.Technical) //add things from the tech catalog { var services = (from s in _catalogController.RequestSupportCatalog(userId) select s).ToList(); searchresults.AddRange(from s in services where searchString != null && s.Name.ToLower().Contains(searchString) select(ICatalogPublishable) s); foreach (var service in services) { //searchresults.AddRange(from o in service.ServiceOptions where searchString != null && o.Name.ToLower().ToLower().Contains(searchString) select (ICatalogPublishable)o); searchresults.AddRange(from c in service.ServiceOptionCategories where searchString != null && c.Name.ToLower().ToLower().Contains(searchString) select(ICatalogPublishable) c); } } searchresults = searchresults.OrderByDescending(a => a.Popularity).ToList(); return(searchresults); }
/// <summary> /// Service Catalog Index, either business, technical, or both /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public ActionResult Index(ServiceCatalog type = ServiceCatalog.Business, int id = 0) { CatalogModel model = new CatalogModel { Catalog = type, CatalogItems = new List <ICatalogPublishable>() }; model.Controls = new CatalogControlsModel { SearchString = "", CatalogType = type }; //setup info for the controls IEnumerable <IServiceDto> services; //lazy loaded data for filtering and use later if (type == ServiceCatalog.Both || type == ServiceCatalog.Business) //add things from the business catalog { services = (from s in _catalogController.RequestBusinessCatalog(UserId) select s).ToList(); foreach (var service in services) //add services to the catalog model { var i = new ServiceSummary { Name = service.Name, Id = service.Id, BusinessValue = service.Description, Options = new List <ICatalogPublishable>() }; if (service.ServiceOptionCategories != null) { i.Options.AddRange((from o in service.ServiceOptionCategories select(ICatalogPublishable) o).ToList()); //find the top 3 items } if (service.ServiceOptions != null) { //i.Options.AddRange((from o in service.ServiceOptions select (ICatalogPublishable) o).ToList()); removed upon request } int take; try { take = ConfigHelper.GetScTopAmount(); } catch (Exception) { take = 3; } i.Options = i.Options.OrderByDescending(o => o.Popularity).Take(take).ToList(); model.CatalogItems.Add(i); } } if (type == ServiceCatalog.Both || type == ServiceCatalog.Technical) //add things from the tech catalog { services = (from s in _catalogController.RequestSupportCatalog(UserId) select s).ToList(); foreach (var service in services) //add services to the catalog model { var i = new ServiceSummary { Name = service.Name, Id = service.Id, BusinessValue = service.Description, Options = new List <ICatalogPublishable>() }; i.Options.AddRange((from o in service.ServiceOptionCategories select(ICatalogPublishable) o).ToList()); //find the top 3 items //i.Options.AddRange((from o in service.ServiceOptions select (ICatalogPublishable)o).ToList()); i.Options = i.Options.OrderByDescending(o => o.Popularity).Take(ConfigHelper.GetScTopAmount()).ToList(); model.CatalogItems.Add(i); } } model.CatalogItems = model.CatalogItems.OrderByDescending(x => x.Popularity).ToList(); if (model.CatalogItems != null && model.CatalogItems.Count > _pageSize) { model.Controls.TotalPages = (model.CatalogItems.Count + _pageSize - 1) / _pageSize; model.CatalogItems = (List <ICatalogPublishable>)model.CatalogItems.Skip(_pageSize * id).Take(_pageSize); } return(View("ServiceCatalog", model)); }