示例#1
0
        public async Task <CustomAttributeIdentifierDto> Handle(AddCustomAttributeCommand message, CancellationToken cancellationToken)
        {
            var detail = new CustomAttributeConfigDetail()
            {
                AttributeDetail     = message.AttributeDetail,
                AttributeName       = message.AttributeKey,
                Category            = message.Category,
                EntityName          = message.ExtendableTypeName,
                CustomAttributeType = message.CustomAttributeType,
                Required            = message.IsRequired,
                Searchable          = message.IsSearchable,
                NumericMaxValue     = message.MaxValue,
                NumericMinValue     = message.MinValue,
                FutureDateOnly      = message.FutureDateOnly.HasValue ? message.FutureDateOnly.Value : false,
                PastDateOnly        = message.PastDateOnly.HasValue ? message.PastDateOnly.Value : false,
                StringMaxLength     = message.MaxLength
            };

            await _customAttributeService.AddCustomAttributeAsync(detail);

            _logger.LogInformation($"----- Custom Attribute {message.AttributeKey} created");

            var newCustomAttribute = _customAttributeRepository.Get(ca => ca.ExtendableTypeName == message.ExtendableTypeName && ca.AttributeKey == message.AttributeKey);

            if (newCustomAttribute == null)
            {
                throw new KeyNotFoundException("Unable to locate new custom attribute");
            }

            var mappedCustomAttribute = _mapper.Map <CustomAttributeIdentifierDto>(newCustomAttribute);

            CreateLinks(mappedCustomAttribute);

            return(mappedCustomAttribute);
        }
示例#2
0
        public async Task AddCustomAttributeAsync(CustomAttributeConfigDetail customAttribute)
        {
            var newCustomAttribute = new CustomAttributeConfiguration()
            {
                ExtendableTypeName  = customAttribute.EntityName,
                Category            = customAttribute.Category,
                AttributeKey        = customAttribute.AttributeName,
                AttributeDetail     = customAttribute.AttributeDetail,
                CustomAttributeType = customAttribute.CustomAttributeType,
                IsRequired          = customAttribute.Required,
                IsSearchable        = customAttribute.Searchable
            };

            switch (newCustomAttribute.CustomAttributeType)
            {
            case CustomAttributeType.Numeric:
                if (customAttribute.NumericMinValue.HasValue)
                {
                    newCustomAttribute.NumericMinValue = customAttribute.NumericMinValue.Value;
                }

                if (customAttribute.NumericMaxValue.HasValue)
                {
                    newCustomAttribute.NumericMaxValue = customAttribute.NumericMaxValue.Value;
                }
                break;

            case CustomAttributeType.String:
                if (customAttribute.StringMaxLength.HasValue)
                {
                    newCustomAttribute.StringMaxLength = customAttribute.StringMaxLength.Value;
                }
                break;

            case CustomAttributeType.DateTime:
                newCustomAttribute.FutureDateOnly = customAttribute.FutureDateOnly;
                newCustomAttribute.PastDateOnly   = customAttribute.PastDateOnly;
                break;

            default:
                break;
            }

            await _customAttributeConfigRepository.SaveAsync(newCustomAttribute);

            if (newCustomAttribute.CustomAttributeType == CustomAttributeType.Selection)
            {
                var newSelectionDataItem = new SelectionDataItem()
                {
                    AttributeKey = customAttribute.AttributeName,
                    Value        = "",
                    SelectionKey = "0"
                };

                await _selectionDataItemRepository.SaveAsync(newSelectionDataItem);
            }
        }
示例#3
0
        public ActionResult EditCustomAttribute(CustomAttributeConfigDetail customAttribute)
        {
            ViewBag.MenuItem = CurrentMenuItem;

            TryValidateModel(customAttribute);
            if (ModelState.IsValid)
            {
                try
                {
                    customAttributeService.UpdateCustomAttribute(customAttribute);

                    return(RedirectToAction("ViewCustomAttributes", new { entityName = customAttribute.EntityName }));
                }
                catch (BusinessException bex)
                {
                    ModelState.AddModelError("Name", bex.Message);
                }
            }

            ViewData.Model = customAttribute;

            List <SelectListItem> listItems = new List <SelectListItem>();
            SelectListItem        listItem  = new SelectListItem {
                Text = "Numeric", Value = "1"
            };

            listItems.Add(listItem);
            listItem = new SelectListItem {
                Text = "String", Value = "2"
            };
            listItems.Add(listItem);
            listItem = new SelectListItem {
                Text = "Selection", Value = "3"
            };
            listItems.Add(listItem);
            listItem = new SelectListItem {
                Text = "DateTime", Value = "4"
            };
            listItems.Add(listItem);

            ViewBag.CustomAttributeTypes = listItems;

            return(View());
        }
示例#4
0
        public async Task UpdateCustomAttributeAsync(CustomAttributeConfigDetail customAttribute)
        {
            var updateCustomAttribute = _unitOfWork.Repository <CustomAttributeConfiguration>().Queryable().Single(ca => ca.ExtendableTypeName == customAttribute.EntityName && ca.AttributeKey == customAttribute.AttributeName);

            updateCustomAttribute.Category        = customAttribute.Category;
            updateCustomAttribute.AttributeDetail = customAttribute.AttributeDetail;
            updateCustomAttribute.IsRequired      = customAttribute.Required;
            updateCustomAttribute.IsSearchable    = customAttribute.Searchable;

            switch (updateCustomAttribute.CustomAttributeType)
            {
            case CustomAttributeType.Numeric:
                if (customAttribute.NumericMinValue.HasValue)
                {
                    updateCustomAttribute.NumericMinValue = customAttribute.NumericMinValue.Value;
                }

                if (customAttribute.NumericMaxValue.HasValue)
                {
                    updateCustomAttribute.NumericMaxValue = customAttribute.NumericMaxValue.Value;
                }
                break;

            case CustomAttributeType.String:
                if (customAttribute.StringMaxLength.HasValue)
                {
                    updateCustomAttribute.StringMaxLength = customAttribute.StringMaxLength.Value;
                }
                break;

            case CustomAttributeType.DateTime:
                updateCustomAttribute.FutureDateOnly = customAttribute.FutureDateOnly;
                updateCustomAttribute.PastDateOnly   = customAttribute.PastDateOnly;
                break;

            default:
                break;
            }

            _customAttributeConfigRepository.Update(updateCustomAttribute);
            await _unitOfWork.CompleteAsync();
        }
示例#5
0
        public async Task <bool> Handle(ChangeCustomAttributeDetailsCommand message, CancellationToken cancellationToken)
        {
            var detail = new CustomAttributeConfigDetail()
            {
                EntityName      = message.ExtendableTypeName,
                AttributeName   = message.AttributeKey,
                AttributeDetail = message.AttributeDetail,
                Category        = message.Category,
                Required        = message.IsRequired,
                Searchable      = message.IsSearchable,
                NumericMaxValue = message.MaxValue,
                NumericMinValue = message.MinValue,
                FutureDateOnly  = message.FutureDateOnly.HasValue ? message.FutureDateOnly.Value : false,
                PastDateOnly    = message.PastDateOnly.HasValue ? message.PastDateOnly.Value : false,
                StringMaxLength = message.MaxLength
            };

            await _customAttributeService.UpdateCustomAttributeAsync(detail);

            _logger.LogInformation($"----- Custom Attribute {message.Id} details updated");

            return(await _unitOfWork.CompleteAsync());
        }