public async Task <IActionResult> PutEscolaEntity(int id, EscolaEntity escolaEntity)
        {
            if (id != escolaEntity.Id)
            {
                return(BadRequest());
            }

            _context.Entry(escolaEntity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EscolaEntityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <EscolaEntity> > PostEscolaEntity(EscolaEntity escolaEntity)
        {
            _context.Escolas.Add(escolaEntity);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetEscolaEntity", new { id = escolaEntity.Id }, escolaEntity));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(EscolaEntity autorEntity)
        {
            if (ModelState.IsValid)
            {
                await _autorService.InsertAsync(autorEntity);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(autorEntity));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <EscolaEntity> > PostEscolaEntity(EscolaEntity escolaEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _escolaService.InsertAsync(escolaEntity);

            return(Ok(escolaEntity));
            //return CreatedAtAction(
            //    "GetEscolaEntity",
            //    new { id = escolaEntity.Id }, escolaEntity);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, EscolaEntity autorEntity)
        {
            if (id != autorEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await _autorService.UpdateAsync(autorEntity);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(autorEntity));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PutEscolaEntity(int id, EscolaEntity escolaEntity)
        {
            if (id != escolaEntity.Id)
            {
                return(BadRequest());
            }

            try
            {
                await _escolaService.UpdateAsync(escolaEntity);
            }
            catch (RepositoryException e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(BadRequest(ModelState));
            }

            return(NoContent());
        }
Ejemplo n.º 7
0
        public async Task UpdateAsync(EscolaEntity updatedEntity)
        {
            var jwtSuccess = await AddAuthJwtToRequest();

            if (!jwtSuccess)
            {
                return;
            }
            var pathWithId = $"{_bibliotecaHttpOptions.CurrentValue.EscolaPath}/{updatedEntity.Id}";

            var httpContent = new StringContent(JsonConvert.SerializeObject(updatedEntity), Encoding.UTF8, "application/json");

            var httpResponseMessage = await _httpClient.PutAsync(pathWithId, httpContent);

            if (!httpResponseMessage.IsSuccessStatusCode)
            {
                await _signInManager.SignOutAsync();
            }
        }
Ejemplo n.º 8
0
 public async Task UpdateAsync(EscolaEntity updatedEntity)
 {
     try
     {
         _context.Update(updatedEntity);
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (await GetByIdAsync(updatedEntity.Id) == null)
         {
             throw new RepositoryException("Livro não encontrado!");
         }
         else
         {
             throw;
         }
     }
 }
Ejemplo n.º 9
0
 public async Task UpdateAsync(EscolaEntity updatedEntity)
 {
     await _escolaRepository.UpdateAsync(updatedEntity);
 }
Ejemplo n.º 10
0
 public async Task InsertAsync(EscolaEntity insertedEntity)
 {
     await _escolaRepository.InsertAsync(insertedEntity);
 }
Ejemplo n.º 11
0
 public async Task InsertAsync(EscolaEntity insertedEntity)
 {
     _context.Add(insertedEntity);
     await _context.SaveChangesAsync();
 }