示例#1
0
        public async Task <ActionResult> Post(Genero genero)
        {
            _contex.Add(genero);
            await _contex.SaveChangesAsync();

            return(Ok(genero));
        }
示例#2
0
        public async Task <IActionResult> PutSection(int id, Section section)
        {
            if (id != section.Id)
            {
                return(BadRequest());
            }
            try
            {
                Section TempSection = _context.Sections.AsNoTracking().FirstOrDefault(x => x.Id == id);
                _context.Entry(section).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                if (TempSection.Title != section.Title)
                {
                    var folderName    = Path.Combine(_hostingEnvironment.WebRootPath, TempSection.Title);
                    var folderNameNew = Path.Combine(_hostingEnvironment.WebRootPath, section.Title);
                    if (Directory.Exists(folderName))
                    {
                        Directory.Move(folderName, folderNameNew);
                    }
                }
            }
            catch (Exception e)
            {
                if (!SectionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok());
        }
示例#3
0
        public async Task <IActionResult> PutArticle([FromRoute] int id, [FromBody] Article article)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
示例#4
0
        public async Task <ActionResult> Post(Persona persona)
        {
            if (!string.IsNullOrEmpty(persona.Foto))
            {
                byte[] fotoPersonas = Convert.FromBase64String(persona.Foto);
                persona.Foto = await _almacenadorArchivos.GuardarArchivo(fotoPersonas, "jpg", "personas");
            }

            _contex.Add(persona);
            await _contex.SaveChangesAsync();

            return(Ok(persona));
        }
示例#5
0
        public async Task <ActionResult <int> > Post(Pelicula pelicula)
        {
            if (!string.IsNullOrWhiteSpace(pelicula.Poster))
            {
                byte[] fotoPoster = Convert.FromBase64String(pelicula.Poster);
                pelicula.Poster = await _almacenadorArchivos.GuardarArchivo(fotoPoster, "jpg", "peliculas");
            }

            if (pelicula.PeliculaActors != null)
            {
                for (int i = 0; i < pelicula.PeliculaActors.Count; i++)
                {
                    pelicula.PeliculaActors[i].Orden = i + 1;
                }
            }
            _context.Add(pelicula);
            await _context.SaveChangesAsync();

            return(pelicula.Id);
        }
        public async Task <ActionResult <SectionUser> > PostSectionUser(SectionUser sectionUser)
        {
            _context.SectionUsers.Add(sectionUser);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (SectionUserExists(sectionUser.SectionId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetSectionUser", new { id = sectionUser.SectionId }, sectionUser));
        }
        public async Task <IActionResult> Delete(int id)
        {
            var bookFromDb = await _db.Book.FirstOrDefaultAsync(u => u.Id == id);

            if (bookFromDb == null)
            {
                return(Json(new { success = false, message = "Error while deleting" }));
            }
            _db.Book.Remove(bookFromDb);
            await _db.SaveChangesAsync();

            return(Json(new { success = true, message = "Delete Successfull" }));
        }
示例#8
0
        public async Task <IActionResult> OnPostDelete(int id)
        {
            var book = await _db.Book.FindAsync(id);

            if (book == null)
            {
                return(NotFound());
            }
            _db.Book.Remove(book);
            await _db.SaveChangesAsync();

            return(RedirectToPage("Index"));
        }
示例#9
0
        public async Task <ActionResult> Votar(VotoPelicula votoPelicula)
        {
            IdentityUser user = await userManager.FindByEmailAsync(HttpContext.User.Identity.Name);

            string       userId     = user.Id;
            VotoPelicula votoActual = await context.VotoPeliculas
                                      .FirstOrDefaultAsync(x => x.PeliculaId == votoPelicula.PeliculaId && x.UserId == userId);

            if (votoActual == null)
            {
                votoPelicula.UserId    = userId;
                votoPelicula.FechaVoto = DateTime.Today;
                context.Add(votoPelicula);
                await context.SaveChangesAsync();
            }
            else
            {
                votoActual.Voto = votoPelicula.Voto;
                await context.SaveChangesAsync();
            }

            return(NoContent());
        }
示例#10
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                await _db.Book.AddAsync(Book);

                await _db.SaveChangesAsync();

                return(RedirectToPage("index"));
            }
            else
            {
                return(Page());
            }
        }
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                var BookFronDb = await _db.Book.FindAsync(Book.id);

                BookFronDb.Name   = Book.Name;
                BookFronDb.Author = Book.Author;
                BookFronDb.ISBN   = Book.ISBN;

                await _db.SaveChangesAsync();

                return(RedirectToPage("index"));
            }
            return(RedirectToPage());
        }
示例#12
0
 public async Task<IActionResult> OnPost()
 {
     if (ModelState.IsValid)
     {
         var bookFromDb = await _db.Book.FindAsync(Book.Id);
         bookFromDb.Name = Book.Name;
         bookFromDb.Author = Book.Author;
         bookFromDb.ISBN = Book.ISBN;
         await _db.SaveChangesAsync();
         return RedirectToPage("Index");
     }
     else
     {
         return Page();
     }
 }
示例#13
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                if (Book.Id == 0)
                {
                    _db.Book.Add(Book);
                }
                else
                {
                    _db.Book.Update(Book);
                }
                await _db.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }
            else
            {
                return(Page());
            }
        }