Ejemplo n.º 1
0
        public async Task <CategoryDTO> GetCategoryAsync(Guid?categoryId)
        {
            Task <CategoryDTO> taskInvoke = Task <CategoryDTO> .Factory.StartNew(() =>
            {
                if (categoryId == null)
                {
                    throw new ArgumentNullException(nameof(categoryId));
                }

                _categoryRepository.Configure();
                var showingCategories = _categoryRepository.GetCategoriesAsync().Result.FirstOrDefault(category => category.Id == categoryId);
                if (showingCategories == null)
                {
                    throw new ArgumentException("There is no categories with specific id", nameof(categoryId));
                }

                CategoryDTO categoryDTO = new CategoryDTO()
                {
                };
                categoryDTO.InjectFrom(showingCategories);
                return(categoryDTO);
            });

            return(await taskInvoke);
        }
Ejemplo n.º 2
0
        public CategoryDTO GetByName(string name)
        {
            CategoryDTO model    = new CategoryDTO();
            var         category = categoryRepository.Get(x => x.Name == name);

            model.InjectFrom(category);
            return(model);
        }
Ejemplo n.º 3
0
        public CategoryDTO GetById(int id)
        {
            CategoryDTO model    = new CategoryDTO();
            var         category = categoryRepository.Get(x => x.Id == id);

            model.InjectFrom(category);
            return(model);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Create(CategoryViewModel categoryVM, string auctionId)
        {
            if (auctionId == null)
            {
                ModelState.AddModelError(string.Empty, Resource.errAuctionNotFound);
            }

            var auction = config.AuctionHouses.Search(auctionId);

            if (auction == null)
            {
                ModelState.AddModelError(string.Empty, Resource.errAuctionNotFound);
            }

            Auctions.SetAuction(auction);

            if (!await _categoryService.IsUnigueNameAsync(categoryVM.Name))
            {
                ModelState.AddModelError("Name", Resource.errNotUnique);
            }

            try
            {
                if (ModelState.IsValid)
                {
                    var categoryDTO = new CategoryDTO()
                    {
                        Id = Guid.NewGuid()
                    };
                    categoryVM.Id = categoryDTO.Id;
                    categoryDTO.InjectFrom(categoryVM);
                    await _categoryService.AddCategoryAsync(categoryDTO);

                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError(string.Empty, "try again");
            }

            DropdownAuction();
            return(View(categoryVM));
        }