コード例 #1
0
ファイル: SlugGenerator.cs プロジェクト: tobsc/FHTW-BA2-BIF
        private static string CheckDuplicates(string value, string entity)
        {
            var slugList = new List <string>();

            try
            {
                switch (entity)
                {
                case "fieldGroup":
                    slugList = _bl.GetFieldGroups().Select(i => i.Slug).ToList();
                    break;

                case "field":
                    slugList = _bl.GetFields().Select(i => i.Slug).ToList();
                    break;

                case "deviceType":
                    slugList = _bl.GetDeviceTypes().Select(i => i.Slug).ToList();
                    break;

                case "orderStatus":
                    slugList = _bl.GetOrderStatus().Select(i => i.Slug).ToList();
                    break;

                case "accessory":
                    slugList = _bl.GetAccessories().Select(i => i.Slug).ToList();
                    break;

                default:
                    break;
                }

                if (!slugList.Any())
                {
                    return(value);
                }
                var filter         = "(" + value + "){1}[-]*[0-9]*";
                var duplicatesList = slugList.Where(x => Regex.IsMatch(x, filter, RegexOptions.IgnoreCase)).ToList();

                if (duplicatesList.Count != 0)
                {
                    value = value + "-" + duplicatesList.Count;
                }
                return(value);
            }
            catch (Exception ex)
            {
                // _log.LogError("Exception: {0}", ex);
                throw;
            }
        }
コード例 #2
0
        public IActionResult GetAccessories()
        {
            try
            {
                var vmdls = _bl.GetAccessories()
                            .ToList()
                            .Select(i => new AccessoryViewModel(i))
                            .ToList();

                return(Ok(vmdls));
            }
            catch (Exception ex)
            {
                _log.LogError("Exception: {0}", ex);
                return(StatusCode(500));
            }
        }