public async Task <IActionResult> PutCategoria(int id, Categoria categoria)
        {
            if (id != categoria.Id)
            {
                return(BadRequest());
            }

            if (!CategoriaExists(id))
            {
                return(NotFound());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                _logger.LogError($"Se presento un error al editar la categoria {id}. Error: {ex.Message} - {ex.StackTrace}");

                return(StatusCode((int)HttpStatusCode.InternalServerError,
                                  new { Mensaje = $"Se presento un error al editar la categoria '{categoria.Nombre}. Error: {ex.Message}" }));
            }

            return(NoContent());
        }
        public virtual async Task <T> Create(T item)
        {
            try
            {
                dataset.Add(item);
                await _context.SaveChangesAsync();

                return(item);
            }
            catch (DbUpdateException ex)
            {
                if (ex.InnerException is SqlException sqlException)
                {
                    int codigoErro = sqlException.Number;
                    if (codigoErro.Equals(2267) || codigoErro.Equals(2601))
                    {
                        throw new InvalidOperationException("O recurso já existe");
                    }
                    if (codigoErro.Equals(547))
                    {
                        throw new InvalidOperationException("Chave Estrangeira já existe");
                    }
                }
                throw ex;
            }
        }
예제 #3
0
        public async Task DeleteAsync(int id)
        {
            var autorModel = await _context.Escolas.FindAsync(id);

            _context.Escolas.Remove(autorModel);
            await _context.SaveChangesAsync();
        }
        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());
        }
예제 #5
0
        public async Task <IActionResult> PutAutor(int id, Autor autor)
        {
            if (id != autor.Id)
            {
                return(BadRequest());
            }

            if (!AutorExists(id))
            {
                return(NotFound());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                _logger.LogInformation($"Se presento un error al editar el autor {autor.Nombres}. Error: {ex.Message} - {ex.StackTrace} ");

                return(StatusCode((int)HttpStatusCode.InternalServerError,
                                  new { Mensaje = $"Se presento un error al editar el autor '{autor.Nombres}. Error: {ex.Message}" }));
            }

            return(NoContent());
        }
        public async Task <ActionResult> Post(Editora editora)
        {
            db.Editoras.Add(editora);
            await db.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = editora.Id }, editora));
        }
예제 #7
0
        public async Task DeleteAsync(int id)
        {
            var livroModel = await _context.Professores.FindAsync(id);

            _context.Professores.Remove(livroModel);
            await _context.SaveChangesAsync();
        }
예제 #8
0
        public async Task <IActionResult> PutAutor(int id, Autor autor)
        {
            autor.Id = id;
            if (id != autor.Id)
            {
                return(BadRequest());
            }
            var autorMod = _context.Autores.Find(id);

            autorMod.Nome      = autor.Nome;
            autorMod.Sobrenome = autor.Sobrenome;
            autorMod.Email     = autor.Email;
            autorMod.Birth     = autor.Birth;

            _context.Autores.Update(autorMod);

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

            return(NoContent());
        }
예제 #9
0
        public async Task <IActionResult> PutLivro(int id, Livro livro)
        {
            livro.Id = id;
            if (id != livro.Id)
            {
                return(BadRequest());
            }
            var livroMod = _context.Livros.Find(id);

            livroMod.Titulo = livro.Titulo;
            livroMod.ISBN   = livro.ISBN;
            livroMod.Ano    = livro.Ano;

            _context.Livros.Update(livroMod);

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

            return(NoContent());
        }
예제 #10
0
        public async Task <IActionResult> PutLibro(int id, Libro libro)
        {
            _logger.LogInformation($"LibrosController: Editar libro {id}");

            if (id != libro.Id)
            {
                return(BadRequest());
            }

            if (!LibroExists(id))
            {
                return(NotFound());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                _logger.LogError($"Se presento un error al editar el libro {id}. Error: {ex.Message} - {ex.StackTrace}");
                return(StatusCode((int)HttpStatusCode.InternalServerError,
                                  new { Mensaje = $"Se presento un error al editar el libro '{libro.Nombre}. Error: {ex.Message}" }));
            }

            return(NoContent());
        }
예제 #11
0
        public async Task <IActionResult> PutAuthor(int id, Author author)
        {
            if (id != author.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #12
0
        public async Task <int> AddAsync(HeroiEntity heroiEntity)
        {
            var entityEntry = await _bibliotecaContext.Herois.AddAsync(heroiEntity);

            await _bibliotecaContext.SaveChangesAsync();

            return(entityEntry.Entity.Id);
        }
예제 #13
0
        public async Task <int> AddAsync(AutorEntity autorEntity)
        {
            var entityEntry = await _bibliotecaContext.Autores.AddAsync(autorEntity);

            await _bibliotecaContext.SaveChangesAsync();

            return(entityEntry.Entity.Id);
        }
예제 #14
0
        public async Task <int> AddAsync(LivroEntity livroEntity)
        {
            var entityEntry = await _bibliotecaContext.Livros.AddAsync(livroEntity);

            await _bibliotecaContext.SaveChangesAsync();

            return(entityEntry.Entity.Id);
        }
예제 #15
0
        public async Task <IActionResult> RegistrarLibro([Bind("cod_lib,ISBN,titulo,autor,editorial,año_pub")] Libro libro)
        {
            if (ModelState.IsValid)
            {
                _context.Add(libro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(libro)));
            }
            return(View(libro));
        }
예제 #16
0
        public async Task <ActionResult> Create([Bind(Include = "CarteId,Titlu,Autor,Editura,AnAparitie")] Carte carte)
        {
            if (ModelState.IsValid)
            {
                db.Carti.Add(carte);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(carte));
        }
예제 #17
0
        public async Task <IActionResult> Create([Bind("IdPais,Nombre")] Pais pais)
        {
            if (ModelState.IsValid)
            {
                pais.IdPais = Guid.NewGuid();
                _context.Add(pais);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pais));
        }
예제 #18
0
        public async Task <IActionResult> Create([Bind("cod_prest,cod_lib,modalidad,fecha_reserva")] prestamo prestamo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(prestamo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["cod_lib"] = new SelectList(_context.libros, "cod_lib", "ISBN", prestamo.cod_lib);
            return(View(prestamo));
        }
예제 #19
0
        public async Task <IActionResult> Create([Bind("IdGenero,Nombre")] Genero genero)
        {
            if (ModelState.IsValid)
            {
                genero.IdGenero = Guid.NewGuid();
                _context.Add(genero);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genero));
        }
예제 #20
0
        public async Task <IActionResult> Create([Bind("IdAutor,Nombre")] Autor autor)
        {
            if (ModelState.IsValid)
            {
                autor.IdAutor = Guid.NewGuid();
                _context.Add(autor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(autor));
        }
예제 #21
0
        public async Task <ActionResult> Create([Bind(Include = "ClientId,Nume,CNP,Adresa,Telefon")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clienti.Add(client);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
예제 #22
0
        public async Task <IActionResult> Create([Bind("IdStatusPrestamo,Nombre")] StatusPrestamo statusPrestamo)
        {
            if (ModelState.IsValid)
            {
                statusPrestamo.IdStatusPrestamo = Guid.NewGuid();
                _context.Add(statusPrestamo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(statusPrestamo));
        }
예제 #23
0
        public async Task <IActionResult> Create([Bind("IdAlumno,Nombre,Matricula,Password,Activo,IdIdentity,Email")] Alumno alumno)
        {
            if (ModelState.IsValid)
            {
                alumno.IdAlumno = Guid.NewGuid();
                _context.Add(alumno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(alumno));
        }
예제 #24
0
        public async Task <IActionResult> Create([Bind("IdEditorial,Nombre")] Editorial editorial)
        {
            if (ModelState.IsValid)
            {
                editorial.IdEditorial = Guid.NewGuid();
                _context.Add(editorial);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index),
                                        new { ac = "Registro insertado con éxito", type = "success" }));
            }

            return(View(editorial));
        }
        public async Task <IActionResult> Create([Bind("IdLibro,IdAutor")] AutorLibro autorLibro)
        {
            if (ModelState.IsValid)
            {
                autorLibro.IdLibro = Guid.NewGuid();
                _context.Add(autorLibro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdAutor"] = new SelectList(_context.Autores, "IdAutor", "IdAutor", autorLibro.IdAutor);
            ViewData["IdLibro"] = new SelectList(_context.Libros, "IdLibro", "IdLibro", autorLibro.IdLibro);
            return(View(autorLibro));
        }
예제 #26
0
        public async Task <ActionResult> Create([Bind(Include = "ImprumutId,ClientId,CarteId,DataImprumut")] Imprumut imprumut)
        {
            if (ModelState.IsValid)
            {
                db.Imprumuturi.Add(imprumut);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CarteId  = new SelectList(db.Carti, "CarteId", "Titlu", imprumut.CarteId);
            ViewBag.ClientId = new SelectList(db.Clienti, "ClientId", "Nume", imprumut.ClientId);
            return(View(imprumut));
        }
예제 #27
0
        public Livro AdicionarLivro(Livro livro)
        {
            try
            {
                _context.Add(livro);
                _context.SaveChangesAsync();

                return livro;
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }
예제 #28
0
        public async Task <IActionResult> Create([Bind("IdPrestamo,IdLibro,IdAlumno,Codigo,FechaPrestamo,FechaLimite,FechaDevolucion,IdStatusPrestamo,MontoMulta")] Prestamo prestamo)
        {
            if (ModelState.IsValid)
            {
                prestamo.IdPrestamo = Guid.NewGuid();
                _context.Add(prestamo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdAlumno"]         = new SelectList(_context.Alumnos, "IdAlumno", "Nombre", prestamo.IdAlumno);
            ViewData["IdLibro"]          = new SelectList(_context.Libros, "IdLibro", "Titulo", prestamo.IdLibro);
            ViewData["IdStatusPrestamo"] = new SelectList(_context.StatusPrestamos, "IdStatusPrestamo", "Nombre", prestamo.IdStatusPrestamo);
            return(View(prestamo));
        }
        public async Task <IActionResult> Insert(Editora editora)
        {
            _context.Editoras.Add(editora);
            await _context.SaveChangesAsync();

            return(Ok(editora));
        }
예제 #30
0
        public async Task <IActionResult> Create([Bind("IdLibro,ISBN,Titulo,IdEditorial,IdGenero,IdPais,Año,Imagen")] Libro libro, IFormFile portada)
        {
            if (ModelState.IsValid)
            {
                libro.Imagen = await GuardarArchivo(portada);

                libro.IdLibro = Guid.NewGuid();
                _context.Add(libro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdEditorial"] = new SelectList(_context.Editoriales, "IdEditorial", "Nombre", libro.IdEditorial);
            ViewData["IdGenero"]    = new SelectList(_context.Generos, "IdGenero", "Nombre", libro.IdGenero);
            ViewData["IdPais"]      = new SelectList(_context.Paises, "IdPais", "Nombre", libro.IdPais);
            return(View(libro));
        }