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(); }
public async Task CreateCatType(CategoryTypeDTO catType) { var catTypeMap = _mapper.Map <CategoryType>(catType); _db.CategoryTypes.Add(catTypeMap); await _db.SaveChangesAsync(); }
public async Task EditCatType(CategoryTypeDTO catType) { var catTypeMap = _mapper.Map <CategoryType>(catType); _db.CategoryTypes.Update(catTypeMap); await _db.SaveChangesAsync(); }
/// <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(); }
/// <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(); }
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)); }
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()); } }
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()); } }
public async Task <IActionResult> OnGet(int Id) { CategoryTypeDTO = await _repo.GetCatType(Id); return(Page()); }