예제 #1
0
        // /////////////                  /////////////              /////////// Biblioteca Usuario


        public static bool AdicionarAnimeBiblioteca(Usuario aux, int?id, Assistidos a) //Adicionar os animes á lista do usuário com uma simples alteração
        {
            Assistidos ass = new Assistidos();                                         //Auxiliar

            Usuario u = AnimesAssistidos(aux);                                         // Me trás todos os animes assistidos desse usuário

            try
            {
                ass = u.AnimesAssistidos.Find(x => x.Anime.IDAnime.Equals(id));//valida se a id já está lá
            }
            catch (System.InvalidOperationException)
            {
                return(false);
            }


            if (ass == null)               // Se não for nulo, adicione esse anime nos assistidos
            {
                u.AnimesAssistidos.Add(a); // Adiciona esse anime a lista de assistidos
                ctx.Entry(u).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Actualiza o guarda una entidad del tipo editorial
        /// </summary>
        private async void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var context = new BibliotecaContext())
                {
                    if (instancia.idEditorial == 0)
                    {
                        instancia.Imagen       = bytesImagen;
                        instancia.FechaIngreso = DateTime.Now.Date;
                        context.Editorial.Add(instancia);
                    }
                    else
                    {
                        instancia.Imagen        = bytesImagen;
                        instancia.FechaModifica = DateTime.Now.Date;
                        context.Editorial.Attach(instancia);
                        context.Entry(instancia).State = EntityState.Modified;
                    }
                    context.SaveChanges();
                    await this.ShowMessageAsync("Exito", "Se guardaron los cambios correctamente");

                    this.Close();
                }
            }
            catch (Exception ex)
            {
                ex.GuardarError();
            }
        }
예제 #3
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());
        }
        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> 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());
        }
        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());
        }
예제 #7
0
        public ActionResult Edit([Bind(Include = "CarteId,Titlu,Autor,Editura,AnAparitie")] Carte carte)
        {
            if (ModelState.IsValid)
            {
                db.Entry(carte).State = EntityState.Modified;
                db.SaveChanges();

                Receive();

                var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
                {
                    var host = sbc.Host(new Uri("rabbitmq://localhost"), h =>
                    {
                        h.Username("guest");
                        h.Password("guest");
                    }
                                        );
                });

                bus.Start();
                // bus.Publish("salot");
                bus.Publish(new Carte(carte.CarteId, carte.Titlu, carte.Autor, carte.Editura, carte.AnAparitie));
                // bus.Publish(new Carte(1,"sal","eugenn","editura",2004));

                System.Diagnostics.Debug.WriteLine("Press any key to exit");


                bus.Stop();



                return(RedirectToAction("Index"));
            }
            return(View(carte));
        }
예제 #8
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());
        }
예제 #9
0
 public ActionResult Edit([Bind(Include = "EditoraId,Nome,Email")] Editora editora)
 {
     if (ModelState.IsValid)
     {
         db.Entry(editora).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(editora);
 }
예제 #10
0
 public ActionResult Edit([Bind(Include = "CarteId,Titlu,Autor,Editura,AnAparitie")] Carte carte)
 {
     if (ModelState.IsValid)
     {
         db.Entry(carte).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(carte));
 }
예제 #11
0
 public ActionResult Editar(Livro livro)
 {
     //Atualiza no banco de dados
     _context.Entry(livro).State = EntityState.Modified;
     _context.SaveChanges();
     //mensagem
     TempData["msg"] = "Livro atualizado!";
     //redirect
     return(RedirectToAction("Listar"));
 }
예제 #12
0
 public ActionResult Edit([Bind(Include = "IdiomaId,nombre")] Idioma idioma)
 {
     if (ModelState.IsValid)
     {
         db.Entry(idioma).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(idioma));
 }
예제 #13
0
 public ActionResult Edit([Bind(Include = "ProductId,Parola")] Loginnn loginnn)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loginnn).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(loginnn));
 }
예제 #14
0
 public ActionResult Edit([Bind(Include = "LectorId,apellido,nombre,telefono,direccion,codigoPostal,observaciones")] Lector lector)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lector).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(lector));
 }
 public ActionResult Edit([Bind(Include = "ClientId,Nume,CNP,Adresa,Telefon")] Client client)
 {
     if (ModelState.IsValid)
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(client));
 }
예제 #16
0
 public ActionResult Edit([Bind(Include = "PaisId,nombre")] Pais pais)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pais).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(pais));
 }
예제 #17
0
 public ActionResult Edit([Bind(Include = "EditorialId,nombre")] Editorial editorial)
 {
     if (ModelState.IsValid)
     {
         db.Entry(editorial).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(editorial));
 }
 public ActionResult Edit([Bind(Include = "NumeroDocumento,Descripcion")] TipoDocumento tipoDocumento)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tipoDocumento).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tipoDocumento));
 }
예제 #19
0
 public ActionResult Edit([Bind(Include = "LectorID,Nombre,Direccion,NumeroDocumento")] Lector lector)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lector).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.NumeroDocumento = new SelectList(db.TipoDocumentoes, "NumeroDocumento", "Descripcion", lector.NumeroDocumento);
     return(View(lector));
 }
예제 #20
0
 public static void add(PrestamoViewModel pvm)
 {
     using (var ctx = new BibliotecaContext())
     {
         Prestamo p = mapper(pvm);
         p.fechaDevolucionTope = p.fechaPrestamo.AddDays(Prestamo.DIAS_PRESTAMO);
         p.fechaDevolucionReal = DateTime.MaxValue;
         ctx.Entry(p).State    = EntityState.Added;
         ctx.SaveChanges();
     }
 }
예제 #21
0
 public ActionResult Edit([Bind(Include = "LivroId,EditoraId,ISBN,Paginas")] Livro livro)
 {
     if (ModelState.IsValid)
     {
         db.Entry(livro).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EditoraId = new SelectList(db.Editoras, "EditoraId", "Nome", livro.EditoraId);
     return(View(livro));
 }
예제 #22
0
 public ActionResult Edit([Bind(Include = "LibroID,Nombre,Autor,GeneroID")] Libros libros)
 {
     if (ModelState.IsValid)
     {
         db.Entry(libros).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GeneroID = new SelectList(db.TipoLibroes, "GeneroID", "DescripcionGenero", libros.GeneroID);
     return(View(libros));
 }
예제 #23
0
 public ActionResult Edit([Bind(Include = "AutorId,nombre,apellido,fechaNac,PaisId")] Autor autor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(autor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PaisId = new SelectList(db.Paises, "PaisId", "nombre", autor.PaisId);
     return(View(autor));
 }
예제 #24
0
 public ActionResult Edit([Bind(Include = "PrestamoId,LectorID,LibroID")] LibroPrestado libroPrestado)
 {
     if (ModelState.IsValid)
     {
         db.Entry(libroPrestado).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LectorID = new SelectList(db.Lectors, "LectorID", "Nombre", libroPrestado.LectorID);
     ViewBag.LibroID  = new SelectList(db.Libros, "LibroID", "Nombre", libroPrestado.LibroID);
     return(View(libroPrestado));
 }
 public ActionResult Edit([Bind(Include = "ImprumutId,ClientId,CarteId,DataImprumut")] Imprumut imprumut)
 {
     if (ModelState.IsValid)
     {
         db.Entry(imprumut).State = EntityState.Modified;
         db.SaveChanges();
         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));
 }
예제 #26
0
 public ActionResult Edit([Bind(Include = "EjemplarId,numeroEjemplar,EstadoId,LibroId")] Ejemplar ejemplar)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ejemplar).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EstadoId = new SelectList(db.Estados, "EstadoId", "nombre", ejemplar.EstadoId);
     ViewBag.LibroId  = new SelectList(db.Libros, "LibroId", "titulo", ejemplar.LibroId);
     return(View(ejemplar));
 }
예제 #27
0
 public ActionResult Edit([Bind(Include = "AlquilerId,LectorId,EjemplarId,fechaSalida,fechaEntrada")] Alquiler alquiler)
 {
     if (ModelState.IsValid)
     {
         db.Entry(alquiler).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EjemplarId = new SelectList(db.Ejemplares, "EjemplarId", "EjemplarId", alquiler.EjemplarId);
     ViewBag.LectorId   = new SelectList(db.Lectores, "LectorId", "apellido", alquiler.LectorId);
     return(View(alquiler));
 }
        public async Task <T> Delete(int id)
        {
            var resultado = await dataset.SingleOrDefaultAsync(i => i.Id.Equals(id));

            try
            {
                if (resultado == null)
                {
                    throw new Exception("O recurso não foi encontrado para exclusão");
                }

                _context.Entry(resultado).State = EntityState.Deleted;
                await _context.SaveChangesAsync();

                return(resultado);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #29
0
 public ActionResult Edit([Bind(Include = "LibroId,titulo,fechaLanza,AutorId,CategoriaId,EditorialId,IdiomaId,paginas,descripcion")] Libro libro)
 {
     if (ModelState.IsValid)
     {
         db.Entry(libro).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AutorId     = new SelectList(db.Autores, "AutorId", "nombre", libro.AutorId);
     ViewBag.CategoriaId = new SelectList(db.Categorias, "CategoriaId", "nombre", libro.CategoriaId);
     ViewBag.EditorialId = new SelectList(db.Editoriales, "EditorialId", "nombre", libro.EditorialId);
     ViewBag.IdiomaId    = new SelectList(db.Idiomas, "IdiomaId", "nombre", libro.IdiomaId);
     return(View(libro));
 }
예제 #30
0
        public virtual async Task <bool> Update(T entity)
        {
            try
            {
                _ctx.Set <T>().Attach(entity);
                _ctx.Entry(entity).State = EntityState.Modified;
                _ctx.SaveChanges();


                return(await Task.FromResult(true));
            }
            catch (Exception e)
            {
                return(await Task.FromResult(false));
            }
        }