コード例 #1
0
        public async Task <Iloscategory> AddILOSCategory(Iloscategory category)
        {
            var result = await _context.Iloscategories.AddAsync(category);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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."));
            }
        }
コード例 #4
0
        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."));
            }
        }
コード例 #5
0
 public async void UpdateILOSCategory(int id, Iloscategory ilosCategory)
 {
     await httpClient.PutAsJsonAsync($"/api/ilosCategories/{id}", ilosCategory);
 }
コード例 #6
0
        public async Task <Iloscategory> CreateILOSCategory(Iloscategory ilosCategory)
        {
            var result = await httpClient.PostAsJsonAsync("/api/ilosCategories", ilosCategory);

            return(await result.Content.ReadAsAsync <Iloscategory>());
        }