public async Task <IActionResult> PostBudgetCategory([FromBody] BudgetCategoryDto budgetCategory) { if (budgetCategory == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var categoryToAdd = Mapper.Map <BudgetCategory>(budgetCategory); _context.Categories.Add(categoryToAdd); try { await _context.SaveChangesAsync(); } catch (DbException) { return(StatusCode(500, "The server was unable to handle your request")); } return(NoContent()); }
public async Task <IActionResult> PutBudgetCategory(Guid id, BudgetCategoryDto budgetCategory) { if (id != budgetCategory.Id) { return(BadRequest()); } if (!await _repository.EntryExists(id)) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var categoryToUpdate = await _repository.GetById(id); Mapper.Map(budgetCategory, categoryToUpdate); await _repository.Update(id, categoryToUpdate); return(NoContent()); }
public async Task <IActionResult> PostBudgetCategory(BudgetCategoryDto budgetCategory) { var categoryToCreate = Mapper.Map <BudgetCategory>(budgetCategory); await _repository.Create(categoryToCreate); return(CreatedAtAction("GetBudgetCategory", new { id = budgetCategory.Id }, budgetCategory)); }
public async Task <IActionResult> OnGetDeletePartialAsync(Guid?id) { if (id.HasValue) { var categoryFromRepo = await _context.Categories.FirstOrDefaultAsync(m => m.Id == id.Value); BudgetCategory = Mapper.Map <BudgetCategoryDto>(categoryFromRepo); if (BudgetCategory != null) { return(new PartialViewResult { ViewName = "_DeletePartial", ViewData = new ViewDataDictionary <BudgetCategoryDto>(ViewData, BudgetCategory) }); } } return(BadRequest()); }
public async Task <IActionResult> OnGetLoadDetailsPartial(Guid?id) { Debug.WriteLine(id.Value); if (!id.HasValue) { return(null); } var categoryFromRepo = await _context.Categories.FirstOrDefaultAsync(m => m.Id == id.Value); if (categoryFromRepo != null) { BudgetCategory = Mapper.Map <BudgetCategoryDto>(categoryFromRepo); return(new PartialViewResult { ViewName = "_DetailsPartial", ViewData = new ViewDataDictionary <BudgetCategoryDto>(ViewData, BudgetCategory) }); } return(null); }
public async Task <IActionResult> OnGetLoadEditPartialAsync(Guid?id) { if (!id.HasValue) { return(NotFound()); } if (!BudgetCategoryExists(id.Value)) { return(NotFound()); } var categoryFromRepo = await _context.Categories.FirstOrDefaultAsync(m => m.Id == id.Value); if (categoryFromRepo == null) { return(BadRequest()); } var mappedCategory = Mapper.Map <BudgetCategoryDto>(categoryFromRepo); BudgetCategory = mappedCategory; if (BudgetCategory == null) { return(NotFound()); } //return Partial("_EditPartial"); return(new PartialViewResult { ViewName = "_EditPartial", ViewData = new ViewDataDictionary <BudgetCategoryDto>(ViewData, BudgetCategory) }); }