Esempio n. 1
0
        public int AddFollow(Follows follows)
        {
            int state = 0;

            using (GramDbContext db = new GramDbContext())
            {
                try
                {
                    Follows detalles = db
                                       .Follows
                                       .Where(x => x.ApplicationUserId == follows.ApplicationUserId && x.Followed.ApplicationUserId == follows.Followed.ApplicationUserId)
                                       .Include(x => x.Followed)
                                       .FirstOrDefault();

                    if (detalles == null)
                    {
                        db.Follows.Add(follows);
                    }
                    else
                    {
                        db.Follows.Remove(detalles);
                        db.Followed.Remove(detalles.Followed);
                    }

                    db.SaveChanges();


                    state = this.IsFollow(follows.ApplicationUserId, follows.Followed.ApplicationUserId) ?  (int)State.isfollow : (int)State.noFollow;
                }
                catch (Exception)
                {
                }
            }
            return(state);
        }
Esempio n. 2
0
        //public List<Foto> GetAllFotosByUserId(String id)
        //{
        //    List<Foto> lista = new List<Foto>();
        //    using(GramDbContext db = new GramDbContext())
        //    {
        //        try
        //        {
        //            lista = db.Foto.Where(x => x.ApplicationUserId == id).ToList();
        //        }
        //        catch (Exception)
        //        {

        //            throw;
        //        }

        //    }
        //    return lista;
        //}

        //public List<Foto> GetAllFotos()
        //{
        //    List<Foto> detalles = new List<Foto>();
        //    using (GramDbContext db = new GramDbContext())
        //    {

        //        try
        //        {
        //            detalles = db.Foto.Include(x => x.User).OrderByDescending(x=> x.Fecha).ToList();
        //        }
        //        catch (Exception e)
        //        {

        //            e.ToString();
        //        }
        //    }
        //    return detalles;

        //}

        public bool AddComment(Comment comment)
        {
            using (GramDbContext db = new GramDbContext())
            {
                try
                {
                    db.Comment.Add(comment);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    e.ToString();
                }
            }
            return(false);
        }
Esempio n. 3
0
        //public void UpdateProfilePicture(User u)
        //{

        //    using (GramDbContext db = new GramDbContext())
        //    {
        //        try
        //        {
        //            db.Usuario.Attach(u);

        //            var entry = db.Entry(u);

        //            entry.Property(e => e.Avatar).IsModified = true;

        //            db.SaveChanges();

        //        }
        //        catch (Exception e)
        //        {

        //            e.ToString();
        //        }
        //    }
        //}

        public bool FotoUploader(Foto foto)
        {
            bool exito = false;

            using (GramDbContext db = new GramDbContext())
            {
                try
                {
                    db.Foto.Add(foto);
                    db.SaveChanges();
                    exito = true;
                }
                catch (Exception e)
                {
                    e.ToString();
                }
            }
            return(exito);
        }
Esempio n. 4
0
        //public bool EliminarFotoPerfil(int userId)
        //{
        //    bool exito = false;
        //    using (GramDbContext db = new GramDbContext())
        //    {
        //        try
        //        {
        //            User u = new User();
        //            u = db.Usuario.Where(x => x.Id == userId).FirstOrDefault();
        //            u.Avatar = "/images/avatar.jpeg";

        //            db.Usuario.Attach(u);

        //            var entry = db.Entry(u);

        //            entry.Property(e => e.Avatar).IsModified = true;

        //            db.SaveChanges();
        //            exito = true;
        //        }
        //        catch (Exception e)
        //        {

        //            e.ToString();
        //        }
        //    }
        //    return exito;
        //}

        public bool BorrarFotoAlbum(int fotoId)
        {
            bool exito = false;

            using (GramDbContext db = new GramDbContext())
            {
                try
                {
                    Foto detalles = db.Foto.Where(x => x.Id == fotoId).FirstOrDefault();
                    db.Foto.Remove(detalles);
                    db.SaveChanges();
                    exito = true;
                }
                catch (Exception e)
                {
                    e.ToString();
                }
            }
            return(exito);
        }