예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public IEnumerable <ProductGroup> GetProductGroups(Func <ProductGroup, bool> where)
 {
     if (@where == null)
     {
         throw new ArgumentException("where");
     }
     return(_roleRepository.GetMany(where));
 }
        /// <summary>
        /// CheckProductReferenceExists
        /// </summary>
        /// <param name="productReference">ProductReference</param>
        /// <returns>Task IAction result (true/false)</returns>
        public async Task <IActionResult> CheckProductReferenceExist(string productReference)
        {
            var result = await _productGroupRepository.GetMany(p => p.ProductReference == productReference);

            if (result.Any())
            {
                return(Content("false"));
            }
            else
            {
                return(Content("true"));
            }
        }
        /// <summary>
        /// Index view
        /// </summary>
        /// <param name="currentFilter">Current search value</param>
        /// <param name="searchString">New search value</param>
        /// <param name="page">Current page number being viewed</param>
        /// <returns>View Paginated list of product groups</returns>
        public async Task <IActionResult> Index(string currentFilter, string searchString, int?page)
        {
            Expression <Func <ProductGroup, bool> > where = p => p.Id != null;
            Expression <Func <ProductGroup, string> > orderby = p => p.ProductReference;

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            if (!String.IsNullOrEmpty(searchString))
            {
                where = p => p.ProductReference.ToUpper().Contains(searchString.ToUpper()) ||
                        p.ProductOwner.ToUpper().Contains(searchString.ToUpper()) ||
                        p.Parent.ProductReference.ToUpper().Contains(searchString.ToUpper());
            }

            int pageSize = 20;

            try
            {
                var productGroupings = _productGroupRepository.GetMany(where, orderby);

                return(View(await PaginatedList <ProductGroup> .CreateAsync(productGroupings.AsNoTracking(), page ?? 1, pageSize)));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(500, ex.Message, ex);

                return(StatusCode(500, ex.Message));
            }
        }
        /// <summary>
        /// Publish product groups in legacy format
        /// </summary>
        /// <returns>Task</returns>
        public async Task Publish()
        {
            var publishFile   = $"{Environment.GetEnvironmentVariable("LegacyProductGroupingLocation", EnvironmentVariableTarget.Machine)}";
            var productGroups = await _productGroupRepository.GetMany();

            XElement export = new XElement("dataroot",
                                           productGroups.Select(p => new XElement("ProductGrouping",
                                                                                  new XElement("ref", p.ProductReference),
                                                                                  new XElement("area", p.Parent?.ProductReference))
                                                                )
                                           );

            await CreateFile(publishFile, export.ToString());

            return;
        }
예제 #5
0
 public async Task <IEnumerable <ProductGroup> > GetProductGroups()
 {
     return((await _productGroupRepository.GetMany()).Where(p => !p.ParentId.HasValue));
 }