Beispiel #1
0
        public CategoryItemVm GetById(Guid Id)
        {
            var entity = _rep.GetById(Id);
            var item   = new CategoryItemVm()
            {
                Id   = entity.Id,
                Name = entity.Name,
                Type = new BootstrapSelectVm()
                {
                    SelectedItem = entity.Type.ToString(), SourceList = _catTypes
                },
            };

            if (entity.ParrentCategory == null)
            {
                item.ParrentCategory = new BootstrapSelectVm()
                {
                    SourceList = _catParrent
                };
            }
            else
            {
                item.ParrentCategory = new BootstrapSelectVm()
                {
                    SelectedItem = entity.ParrentCategory.Id.ToString(), SourceList = _catParrent
                };
            }
            return(item);
        }
        public async Task<CategoryItemVm> GetCurrentCategory(IUnitOfWork uofw, int id)
        {
            var categoryItem = new CategoryItemVm();

            var cat = await _contentCategoryService.GetAll(uofw).Where(x => x.ID == id).FirstOrDefaultAsync();

            if (cat != null)
            {
                categoryItem.Id = cat.ID;
                categoryItem.Title = cat.Name;
                categoryItem.Mnemonic = cat.CategoryItemMnemonic;
                categoryItem.ImageId = cat.ImageID.HasValue ? cat.Image.FileID.ToString() : string.Empty;
                categoryItem.Expand = cat.Expanded;
                categoryItem.Desciption = cat.PublicTitle;
                categoryItem.Color = string.IsNullOrEmpty(cat.Color) ? "#4a4560" : cat.Color;
            }

            return categoryItem;
        }
Beispiel #3
0
        public void AddOrUpdateCategory(CategoryItemVm vm)
        {
            Category entity = vm.Id == Guid.Empty ? new Category()
            {
                Id = Guid.NewGuid()
            } : _rep.GetById(vm.Id);

            entity.Name = vm.Name;
            Guid parrenId = Guid.Empty;

            Guid.TryParse(vm.ParrentCategory.SelectedItem, out parrenId);
            entity.ParrentCategory = parrenId == Guid.Empty ? null : _rep.GetById(parrenId);
            entity.Type            = vm.Type.SelectedItem == "Incoming" ? CategoryType.Incoming : CategoryType.Outcoming;

            if (vm.Id == Guid.Empty)
            {
                _rep.Insert(entity);
            }
            else
            {
                _rep.Update(entity);
            }
            _rep.Save();
        }