Exemplo n.º 1
0
        public ResponseApiError Delete(int id)
        {
            try
            {
                ResponseApiError responseApiError = ValidateExist(id);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }


                Secciones seccion = db.Secciones
                                    .Include(x => x.Colores)
                                    .FirstOrDefault(x => x.iD_Seccion == id);

                db.Remove(seccion);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public ResponseApiError Update(Secciones seccion, int id)
        {
            try
            {
                ResponseApiError responseApiError = Validate(seccion);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                responseApiError = ValidateExist(id);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                Secciones seccionEdit = db.Secciones.First(x => x.iD_Seccion == id);

                seccionEdit.nombre_Seccion = seccion.nombre_Seccion;

                seccionEdit.color = seccion.color;

                seccionEdit.pos = seccion.pos;


                db.Update(seccionEdit);
                db.SaveChanges();
                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public ResponseApiError Update(Perfiles perfil, int id)
        {
            try
            {
                ResponseApiError responseApiError = Validate(perfil);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                responseApiError = ValidateExist(id);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                Perfiles perfilDb = db.Perfiles.First(x => x.iD_Perfil == id);
                perfilDb.tipo_Perfil = perfil.tipo_Perfil;


                db.Update(perfilDb);
                db.SaveChanges();
                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
0
        public ResponseApiError Delete(int id)
        {
            try
            {
                ResponseApiError responseApiError = ValidateExist(id);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }


                Noticias noticia = db.Noticias
                                   .Include(x => x.Usuario)
                                   .FirstOrDefault(x => x.iD_Noticia == id);

                db.Remove(noticia);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 5
0
        public IActionResult Create([FromBody] Comentarios comentario)
        {
            Claim  userIdClaim = User.Claims.FirstOrDefault(x => x.Type.Contains("nameIdentifier"));
            string userId      = userIdClaim.Value;

            try
            {
                comentariosCore = new ComentariosCore(db);
                ResponseApiError responseApiError = comentariosCore.Create(comentario, userId);

                if (responseApiError != null)
                {
                    return(StatusCode(responseApiError.HttpStatusCode, responseApiError));
                }

                return(Ok(new ResponseApiSuccess {
                    Code = 1, Message = "Comentario posteado"
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiError {
                    Code = 1001, Message = ex.Message
                }));
            }
        }
Exemplo n.º 6
0
        public IActionResult Update([FromBody] Noticias noticia, [FromRoute] int id)
        {
            Claim  userIdClaim = User.Claims.FirstOrDefault(x => x.Type.Contains("nameIdentifier"));
            string userId      = userIdClaim.Value;

            try
            {
                noticiasCore = new NoticiasCore(db);
                ResponseApiError responseApiError = noticiasCore.Update(noticia, id, userId);

                if (responseApiError != null)
                {
                    return(StatusCode(responseApiError.HttpStatusCode, responseApiError));
                }

                return(Ok(new ResponseApiSuccess {
                    Code = 1, Message = "Noticia modificada"
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiError {
                    Code = 1001, Message = ex.Message
                }));
            }
        }
Exemplo n.º 7
0
        public ResponseApiError Delete(string username)
        {
            try
            {
                ResponseApiError responseApiError = ValidateExist(username);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                Usuario usuario = db.Usuario
                                  .Include(x => x.Perfiles)
                                  .FirstOrDefault(x => x.UserName == username);

                // IQueryable<Perfiles> perfiles = db.Perfiles.Where(x => x.iD_Perfil == id); ESTO VA EN USUARIOS
                //db.RemoveRange(perfiles);

                db.Remove(usuario);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        public ResponseApiError Update(Noticias noticia, int id, string userId)
        {
            try
            {
                ResponseApiError responseApiError = Validate(noticia, userId);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                responseApiError = ValidateExist(id);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                Noticias noticiaEdit = db.Noticias.First(x => x.iD_Noticia == id);

                noticiaEdit.paisF = noticia.paisF;

                noticiaEdit.ciudadF = noticia.ciudadF;

                noticiaEdit.coloniaF = noticia.coloniaF;

                noticiaEdit.fecha_Hora_Acontecimiento = noticia.fecha_Hora_Acontecimiento;

                noticiaEdit.fecha_Publicacion = noticia.fecha_Publicacion;

                noticiaEdit.titulo_Noticia = noticia.titulo_Noticia;

                noticiaEdit.descripcion_Noticia = noticia.descripcion_Noticia;

                noticiaEdit.texto_Noticia = noticia.texto_Noticia;

                noticiaEdit.palabra_Clave = noticia.palabra_Clave;

                noticiaEdit.seccion_Noticia = noticia.seccion_Noticia;

                noticiaEdit.estatus_Noticia = noticia.estatus_Noticia;

                noticiaEdit.likes = noticia.likes;

                noticiaEdit.visitas = noticia.visitas;

                noticiaEdit.comentarios_editor = noticia.comentarios_editor;

                noticiaEdit.texto_Noticia = noticia.texto_Noticia;



                db.Update(noticiaEdit);
                db.SaveChanges();
                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 9
0
        public ResponseApiError Create(Comentarios comentario, string userId)
        {
            try
            {
                ResponseApiError responseApiError = Validate(comentario, userId);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }
                comentario.autor = userId;
                db.Add(comentario);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 10
0
        public ResponseApiError Create(Secciones seccion)
        {
            try
            {
                ResponseApiError responseApiError = Validate(seccion);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                db.Add(seccion);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 11
0
        public ResponseApiError Create(Noticias noticia, string userId)
        {
            try
            {
                ResponseApiError responseApiError = Validate(noticia, userId);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }
                noticia.autor = userId;
                db.Add(noticia);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 12
0
        public ResponseApiError Update(CreateUserRequest createUserRequest, string username)
        {
            try
            {
                ResponseApiError responseApiError = Validate(createUserRequest);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                responseApiError = ValidateExist(username);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                Usuario usuarioDb = db.Usuario.First(x => x.UserName == username);

                usuarioDb.nombre = createUserRequest.nombre;

                usuarioDb.apellido = createUserRequest.apellido;

                usuarioDb.Email = createUserRequest.Email;

                usuarioDb.UserName = createUserRequest.UserName;

                usuarioDb.PhoneNumber = createUserRequest.PhoneNumber;

                usuarioDb.perfil = createUserRequest.perfil;



                db.Update(usuarioDb);
                db.SaveChanges();
                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 13
0
        public IActionResult Update([FromBody] CreateUserRequest usuario, [FromRoute] string username)
        {
            try
            {
                usuariosCore = new UsuariosCore(db);
                ResponseApiError responseApiError = usuariosCore.Update(usuario, username);

                if (responseApiError != null)
                {
                    return(StatusCode(responseApiError.HttpStatusCode, responseApiError));
                }
                return(Ok(new ResponseApiSuccess {
                    Code = 1, Message = "Usuario modificado"
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiError {
                    Code = 1001, Message = ex.Message
                }));
            }
        }
Exemplo n.º 14
0
        public ResponseApiError Delete(int id)
        {
            try
            {
                ResponseApiError responseApiError = ValidateExist(id);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }

                Perfiles perfil = db.Perfiles.FirstOrDefault(x => x.iD_Perfil == id);
                //Perfiles perfil = db.Perfiles.Find(id); OTRO TIPODE BUSQUEDA


                db.Remove(perfil);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 15
0
        public IActionResult Delete([FromRoute] int id)
        {
            try
            {
                comentariosCore = new ComentariosCore(db);
                ResponseApiError responseApiError = comentariosCore.Delete(id);

                if (responseApiError != null)
                {
                    return(StatusCode(responseApiError.HttpStatusCode, responseApiError));
                }

                return(Ok(new ResponseApiSuccess {
                    Code = 1, Message = "Comentario Eliminado"
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiError {
                    Code = 1001, Message = ex.Message
                }));
            }
        }
Exemplo n.º 16
0
        public IActionResult Update([FromBody] Perfiles perfil, [FromRoute] int id)
        {
            try
            {
                perfilesCore = new PerfilesCore(db);
                ResponseApiError responseApiError = perfilesCore.Update(perfil, id);

                if (responseApiError != null)
                {
                    return(StatusCode(responseApiError.HttpStatusCode, responseApiError));
                }

                return(Ok(new ResponseApiSuccess {
                    Code = 1, Message = "Perfil modificado"
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiError {
                    Code = 1001, Message = ex.Message
                }));
            }
        }
Exemplo n.º 17
0
        public IActionResult Create([FromBody] Secciones seccion)
        {
            try
            {
                seccionesCore = new SeccionesCore(db);
                ResponseApiError responseApiError = seccionesCore.Create(seccion);

                if (responseApiError != null)
                {
                    return(StatusCode(responseApiError.HttpStatusCode, responseApiError));
                }

                return(Ok(new ResponseApiSuccess {
                    Code = 1, Message = "Seccion creada"
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseApiError {
                    Code = 1001, Message = ex.Message
                }));
            }
        }
Exemplo n.º 18
0
        public ResponseApiError Delete(int id)
        {
            try
            {
                ResponseApiError responseApiError = ValidateExist(id);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }


                Comentarios comentario = db.Comentarios
                                         .FirstOrDefault(x => x.iD_Comentarios == id);

                db.Remove(comentario);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 19
0
        public ResponseApiError Delete(int id)
        {
            try
            {
                ResponseApiError responseApiError = ValidateExist(id);
                if (responseApiError != null)
                {
                    return(responseApiError);
                }


                Respuestas respuesta = db.Respuestas
                                       .FirstOrDefault(x => x.iD_Respuesta == id);

                db.Remove(respuesta);
                db.SaveChanges();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }