Exemplo n.º 1
0
        public async Task <ActionResult <Anime_Favorito> > CrearAnime_Favoritos([FromBody][Bind("animeId")] int animeId)
        {
            try
            {
                Claim correo = User.Claims.FirstOrDefault(c => c.Type == "Email");

                if (correo != null)
                {
                    Usuario usuario = await _userManager.FindByEmailAsync(correo.Value);

                    Anime_Favorito af = new Anime_Favorito()
                    {
                        Usuario  = usuario,
                        Anime    = _context.Animes.Find(animeId),
                        Favorito = true
                    };

                    _context.Add(af);
                    await _context.SaveChangesAsync();

                    return(Ok(new ApiResponseFormat {
                        Estado = StatusCodes.Status201Created, Mensaje = "Anime favorito agregado", Dato = af.Favorito
                    }));
                }

                return(Unauthorized(new ApiResponseFormat {
                    Estado = StatusCodes.Status401Unauthorized, Mensaje = "Inicie sesion para usar esta opcion."
                }));
            }
            catch (DbUpdateException ex)
            {
                return(StatusCode(ex.HResult, new { Result = ex.HResult, Data = ex.Message }));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AgregarManga([FromBody] MangaCrearViewModel mangas)
        {
            Manga newmanga = new Manga()
            {
                Descripcion       = mangas.Descripcion,
                Nombre            = mangas.Nombre,
                Fecha_publicacion = mangas.Fecha_publicacion,
                Fecha_subida      = DateTime.UtcNow
            };

            if (mangas.Portada != null)
            {
                MemoryStream ms = new MemoryStream();
                mangas.Portada.CopyTo(ms);
                newmanga.Portada = ms.ToArray();
            }
            else
            {
                newmanga.Portada = System.IO.File.ReadAllBytes("./wwwroot/14671207_791293424306921_4080708202123646799_n.jpg.jpg");
            }

            await AniadirGeneros(newmanga, mangas.GenerosActivos.Where(ga => ga.Activo).Select(ga => ga.Genero).ToList());

            try
            {
                _context.Add(newmanga);
                await _context.SaveChangesAsync();

                return(StatusCode(StatusCodes.Status201Created, new ApiResponseFormat()
                {
                    Estado = StatusCodes.Status201Created, Mensaje = $"Manga {newmanga.Nombre} agregado exitosamente", Dato = newmanga
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new ApiResponseFormat()
                {
                    Estado = StatusCodes.Status400BadRequest, Mensaje = ex.Message
                }));
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult <Manga_Favorito> > PostManga_Favoritos(int mangaId)
        {
            Claim correo = User.Claims.FirstOrDefault(c => c.Type == "Email");

            if (correo != null)
            {
                Usuario usuario = await _userManager.FindByEmailAsync(correo.Value);

                Manga manga = _context.Mangas.Find(mangaId);

                Manga_Favorito af = new Manga_Favorito()
                {
                    Usuario  = usuario,
                    Manga    = manga,
                    Favorito = true
                };

                try
                {
                    _context.Add(af);
                    await _context.SaveChangesAsync();

                    return(Ok(new ApiResponseFormat()
                    {
                        Estado = StatusCodes.Status201Created, Mensaje = $"{manga.Nombre} agregado a favoritos", Dato = af.Favorito
                    }));
                }
                catch (Exception ex)
                {
                    return(BadRequest(new ApiResponseFormat()
                    {
                        Estado = ex.HResult, Mensaje = ex.Message
                    }));
                }
            }

            return(Unauthorized(new { Result = StatusCodes.Status401Unauthorized, Data = "Inicie sesion para usar esta opcion." }));
        }