Пример #1
0
        public async Task<ActionResult> CategoryUpdate(int? id)
        {
            Category category;

            if (id.HasValue)
                category = await _categoryService.FindAsync(id);
            else
                category = new Category() { Enabled = true };

            return View(category);
        }
Пример #2
0
        public async Task<ActionResult> CategoryUpdate(Category category)
        {
            if (category.ID == 0)
            {
                category.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added;
                category.Parent = 0;

                _categoryService.Insert(category);
            }
            else
            {
                var categoryExisting = await _categoryService.FindAsync(category.ID);

                categoryExisting.Name = category.Name;
                categoryExisting.Description = category.Description;
                categoryExisting.Enabled = category.Enabled;

                categoryExisting.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Modified;

                _categoryService.Update(categoryExisting);
            }

            await _unitOfWorkAsync.SaveChangesAsync();

            _dataCacheService.RemoveCachedItem(CacheKeys.Categories);

            return RedirectToAction("Categories");
        }
Пример #3
0
        public async Task<ActionResult> CategoryUpdate(int? id)
        {
            Category category;

            var categoryModel = new CategoryModel();

            var ListingTypes = await _ListingTypeService.Query().SelectAsync();
            categoryModel.ListingTypes = ListingTypes.ToList();

            if (id.HasValue)
            {
                category = await _categoryService.FindAsync(id);
                var categoryListingTypes = await _categoryListingTypeService.Query(x => x.CategoryID == id.Value).SelectAsync();
                categoryModel.CategoryListingTypeID = categoryListingTypes.Select(x => x.ListingTypeID).ToList();
            }
            else
                category = new Category() { Enabled = true };

            categoryModel.Category = category;

            return View(categoryModel);
        }