Пример #1
0
 public static IQueryable<SelectListItem> GetCategorySelectOptions(ICategoryServices categoryServices, int accountId, CategoryTypeDTO type)
 {
     return categoryServices.All().Where(x => x.Type == type && x.Account_AccountID == accountId).Select(x => new SelectListItem {
         Value = x.CategoryID.ToString(),
         Text = x.Name
     }).AsQueryable();
 }
Пример #2
0
        public async Task CreateCatType(CategoryTypeDTO catType)
        {
            var catTypeMap = _mapper.Map <CategoryType>(catType);

            _db.CategoryTypes.Add(catTypeMap);
            await _db.SaveChangesAsync();
        }
Пример #3
0
        public async Task EditCatType(CategoryTypeDTO catType)
        {
            var catTypeMap = _mapper.Map <CategoryType>(catType);

            _db.CategoryTypes.Update(catTypeMap);

            await _db.SaveChangesAsync();
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="categoryTypeDTO"></param>
        /// <returns></returns>
        public async Task UpdateItem(CategoryTypeDTO categoryTypeDTO)
        {
            var categoryTypeEntity = _mapper.Map <CategoryType>(categoryTypeDTO);

            _dbContext.CategoryTypes.Update(categoryTypeEntity);

            await _dbContext.SaveChangesAsync();
        }
Пример #5
0
        /// <summary>
        /// Insert item categoryType to table and save.
        /// </summary>
        /// <param name="categoryType"></param>
        /// <returns></returns>
        public async Task InsertItem(CategoryTypeDTO categoryType)
        {
            var categoryTypeEntity = _mapper.Map <CategoryType>(categoryType);

            _dbContext.CategoryTypes.Add(categoryTypeEntity);

            await _dbContext.SaveChangesAsync();
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind] CategoryTypeDTO categoryType)
        {
            if (ModelState.IsValid)
            {
                var ItemsToReturn = _mapper.Map <CategoryType>(categoryType);

                _repo.CreateCatType(ItemsToReturn);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoryType));
        }
Пример #7
0
        public async Task <ActionResult> PostCategoryType(CategoryTypeDTO categoryTypeDTO)
        {
            try
            {
                await _service.InsertItem(categoryTypeDTO);

                return(CreatedAtAction("GetCategoryType", new { id = categoryTypeDTO.CategoryTypeId }, categoryTypeDTO));
            }

            catch (Exception ex)
            {
                Log.LogError($"Chyba při ukládání do databáze: {ex.InnerException}");
                return(NotFound());
            }
        }
Пример #8
0
        public async Task <IActionResult> PutCategoryType(int id, CategoryTypeDTO categoryTypeDTO)
        {
            if (id != categoryTypeDTO.CategoryTypeId)
            {
                Log.LogError($"Chyba!!! Záznam s tímto Id nebyl nalezen.");
                return(BadRequest());
            }

            try
            {
                await _service.UpdateItem(categoryTypeDTO);

                return(CreatedAtAction("GetCategoryType", new { id = categoryTypeDTO.CategoryTypeId }, id));
            }

            catch (Exception ex)
            {
                Log.LogError($"Chyba při ukládání do databáze: {ex.InnerException}");
                return(NotFound());
            }
        }
Пример #9
0
        public async Task <IActionResult> OnGet(int Id)
        {
            CategoryTypeDTO = await _repo.GetCatType(Id);

            return(Page());
        }