public async Task <Iloscategory> AddILOSCategory(Iloscategory category) { var result = await _context.Iloscategories.AddAsync(category); await _context.SaveChangesAsync(); return(result.Entity); }
public async Task <Iloscategory> UpdateILOSCategory(Iloscategory category) { var result = await _context.Iloscategories.FirstOrDefaultAsync(s => s.Id == category.Id); if (result != null) { result.Category = category.Category; await _context.SaveChangesAsync(); return(result); } return(null); }
public async Task <ActionResult <Iloscategory> > CreateILOSCategory(Iloscategory category) { try { if (category == null) { return(BadRequest()); } var createdILOSCategory = await _categoryRepository.AddILOSCategory(category); return(createdILOSCategory); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database.")); } }
public async Task <ActionResult <Iloscategory> > UpdateILOSCategory(int id, Iloscategory category) { try { if (id != category.Id) { return(BadRequest()); } var ILOSCategoryToUpdate = await _categoryRepository.GetILOSCategory(id); if (ILOSCategoryToUpdate == null) { return(NotFound($"ILOSCategory with id = {id} not found")); } return(await _categoryRepository.UpdateILOSCategory(category)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database.")); } }
public async void UpdateILOSCategory(int id, Iloscategory ilosCategory) { await httpClient.PutAsJsonAsync($"/api/ilosCategories/{id}", ilosCategory); }
public async Task <Iloscategory> CreateILOSCategory(Iloscategory ilosCategory) { var result = await httpClient.PostAsJsonAsync("/api/ilosCategories", ilosCategory); return(await result.Content.ReadAsAsync <Iloscategory>()); }