コード例 #1
0
        public async Task <ActionResult <AdsFamilyViewModel> > Create(AdsFamilyViewModel familyView)
        {
            if (familyView == null)
            {
                return(BadRequest());
            }

            if (familyView.FamilyId == Guid.Empty)
            {
                familyView.FamilyId = Guid.NewGuid();

                foreach (var item in familyView.Attributes)
                {
                    item.FamilyId          = familyView.FamilyId;
                    item.FamilyAttributeId = Guid.NewGuid();
                }
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var entity = await _adsUnitOfWork.FamiliesRepository.Add(familyView);

            return(Created($"{familyView.FamilyId}", familyView));
        }
コード例 #2
0
        void SelectFamily(ChangeEventArgs e, AdsFamilyViewModel family)
        {
            bool isChecked = e.Value.ToString() == "on";

            if (isChecked)
            {
                if (string.IsNullOrEmpty(_options.Family))
                {
                    _options.Family = family.FamilyId.ToString();
                }
                else
                {
                    var items = new List <string>(_options.Family.Split(';'))
                    {
                        family.FamilyId.ToString()
                    };

                    _options.Family = string.Join(';', items);
                }
            }
            else if (!string.IsNullOrEmpty(_options.Family))
            {
                var list = new List <string>(_options.Family.Split(';'));
                list.Remove(family.FamilyId.ToString());
                _options.Family = string.Join(';', list);
            }
        }
コード例 #3
0
 private async Task OpenFilterCategory(AdsFamilyViewModel model)
 {
     RefAds.Families.ForEach(x => x.Categories.ForEach(f => f.Selected = false));
     FamilySelected     = model;
     ShowFilterCountry  = false;
     ShowFilterCategory = true;
     await InvokeAsync(StateHasChanged);
 }
コード例 #4
0
 private void SelectFamily(AdsFamilyViewModel family)
 {
     family.Categories.ForEach(x => x.Selected = false);
     FamilySelected = family;
     FamilySearch   = FamilySelected.Label;
     ListCateg      = family.Categories;
     ShowFamily     = false;
     ShowCategory   = true;
     StateHasChanged();
 }
コード例 #5
0
        bool IsFamilySelected(AdsFamilyViewModel family)
        {
            if (_options == null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(_options.Family))
            {
                return(false);
            }

            var list = new List <string>(_options.Family.Split(';'));

            return(list.Contains(family.FamilyId.ToString()));
        }
コード例 #6
0
        public async Task <ActionResult <AdsFamilyViewModel> > Update(Guid id, AdsFamilyViewModel familyView)
        {
            if (familyView == null)
            {
                return(BadRequest());
            }

            if (familyView.FamilyId != id)
            {
                return(BadRequest());
            }

            if (familyView.Attributes.Any(a => a.FamilyAttributeId == Guid.Empty))
            {
                foreach (var familyAttribute in familyView.Attributes.Where(a => a.FamilyAttributeId == Guid.Empty))
                {
                    familyAttribute.FamilyId          = id;
                    familyAttribute.FamilyAttributeId = Guid.NewGuid();
                }
            }

            var vm = await _adsUnitOfWork.FamiliesRepository.Update(familyView);

            foreach (var attribute in familyView.Attributes)
            {
                if (vm.Attributes.Any(a => a.FamilyAttributeId == attribute.FamilyAttributeId))
                {
                    await _adsUnitOfWork.FamilyAttributesRepository.Update(attribute);
                }
                else
                {
                    await _adsUnitOfWork.FamilyAttributesRepository.Add(attribute);
                }
            }

            var attributes = await _adsUnitOfWork.FamilyAttributesRepository.GetByFamily(familyView.FamilyId);

            foreach (var attribute in attributes.Except(familyView.Attributes, model => model.FamilyAttributeId))
            {
                await _adsUnitOfWork.FamilyAttributesRepository.Remove(attribute.FamilyAttributeId);
            }

            var result = await _adsUnitOfWork.FamiliesRepository.Get(familyView.FamilyId);

            return(Ok(result));
        }
コード例 #7
0
        private async Task ParseFamily(AdsFamilyViewModel family, IList <ExchangeDataRow> models)
        {
            models.Add(new ExchangeDataRow
            {
                Type              = "Family",
                FamilyId          = family.FamilyId.ToString(),
                Code              = family.Code,
                Label             = family.Label,
                LabelSearch       = family.LabelSearch,
                UrlApi            = family.UrlApi,
                MetaTitle         = family.MetaTitle,
                MetaDescription   = family.MetaDescription,
                MetaKeywords      = family.MetaKeywords,
                PurchaseLabelRule = family.PurchaseLabelRule
            });

            var attributes = await _adsUnitOfWork.FamilyAttributesRepository.GetByFamily(family.FamilyId);

            if (attributes != null && attributes.Any())
            {
                foreach (var attribute in attributes)
                {
                    models.Add(new ExchangeDataRow
                    {
                        Type              = "Attribute",
                        FamilyId          = family.FamilyId.ToString(),
                        FamilyAttributeId = attribute.FamilyAttributeId.ToString(),
                        Code              = attribute.Code,
                        Label             = attribute.Label,
                        IsRequired        = attribute.IsRequired.ToString(),
                        IsSearchable      = attribute.IsSearchable.ToString(),
                        AttributeType     = attribute.Type
                    });
                }
            }
        }
コード例 #8
0
        private async Task <AdsFamilyViewModel> ImportFamily(ExchangeDataRow item, AdsImportResultViewModel importResult)
        {
            if (!Guid.TryParse(item.FamilyId, out var familyId))
            {
                _logger.LogWarning($"ParentId:{item.FamilyId} is not a guid");
            }

            var current = await _adsUnitOfWork.FamiliesRepository.Get(familyId);

            if (current == null)
            {
                _logger.LogInformation($"Create new family with id {familyId} code {item.Code} label {item.Label}");

                current = new AdsFamilyViewModel()
                {
                    Code              = item.Code,
                    FamilyId          = familyId,
                    Label             = item.Label,
                    LabelSearch       = item.LabelSearch,
                    HeaderAuthorize   = item.HeaderAuthorize,
                    MetaDescription   = item.MetaDescription,
                    MetaKeywords      = item.MetaKeywords,
                    MetaTitle         = item.MetaTitle,
                    PictureUrl        = item.PictureUrl,
                    UrlApi            = item.UrlApi,
                    PurchaseLabelRule = item.PurchaseLabelRule
                };

                importResult.FamiliesAdded += 1;
                await _adsUnitOfWork.FamiliesRepository.Add(current);
            }
            else if (item.Type.Equals("family", StringComparison.OrdinalIgnoreCase))
            {
                _logger.LogInformation($"Update family with id {familyId} code {current.Code} label {current.Label}");

                bool hasChanged = false;

                if (current.Code != item.Code)
                {
                    hasChanged   = true;
                    current.Code = item.Code;
                }

                if (current.Label != item.Label)
                {
                    hasChanged    = true;
                    current.Label = item.Label;
                }

                if (current.LabelSearch != item.LabelSearch)
                {
                    hasChanged          = true;
                    current.LabelSearch = item.LabelSearch;
                }

                if (current.HeaderAuthorize != item.HeaderAuthorize)
                {
                    hasChanged = true;
                    current.HeaderAuthorize = item.HeaderAuthorize;
                }

                if (current.MetaDescription != item.MetaDescription)
                {
                    hasChanged = true;
                    current.MetaDescription = item.MetaDescription;
                }

                if (current.MetaKeywords != item.MetaKeywords)
                {
                    hasChanged           = true;
                    current.MetaKeywords = item.MetaKeywords;
                }

                if (current.MetaTitle != item.MetaTitle)
                {
                    hasChanged        = true;
                    current.MetaTitle = item.MetaTitle;
                }

                if (current.PictureUrl != item.PictureUrl)
                {
                    hasChanged         = true;
                    current.PictureUrl = item.PictureUrl;
                }

                if (current.UrlApi != item.UrlApi)
                {
                    hasChanged     = true;
                    current.UrlApi = item.UrlApi;
                }

                if (current.PurchaseLabelRule != item.PurchaseLabelRule)
                {
                    hasChanged = true;
                    current.PurchaseLabelRule = item.PurchaseLabelRule;
                }

                if (hasChanged)
                {
                    importResult.FamiliesUpdated += 1;
                    await _adsUnitOfWork.FamiliesRepository.Update(current);
                }
            }

            return(current);
        }