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));
        }
        public async Task <IActionResult> Create(EscolaEntity autorEntity)
        {
            if (ModelState.IsValid)
            {
                await _autorService.InsertAsync(autorEntity);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(autorEntity));
        }
Exemple #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);
        }
        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));
        }
Exemple #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());
        }
        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();
            }
        }
 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;
         }
     }
 }
Exemple #9
0
 public async Task UpdateAsync(EscolaEntity updatedEntity)
 {
     await _escolaRepository.UpdateAsync(updatedEntity);
 }
Exemple #10
0
 public async Task InsertAsync(EscolaEntity insertedEntity)
 {
     await _escolaRepository.InsertAsync(insertedEntity);
 }
 public async Task InsertAsync(EscolaEntity insertedEntity)
 {
     _context.Add(insertedEntity);
     await _context.SaveChangesAsync();
 }