Beispiel #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);
        }
Beispiel #2
0
 public HomeController(
     IFotoRepository fotoRepository,
     ICommentRepository commentRepository,
     IUserRepository userRepository,
     UserManager <ApplicationUser> userManager,
     GramDbContext context
     )
 {
     _fotoRepository    = fotoRepository;
     _commentRepository = commentRepository;
     _userRepository    = userRepository;
     _userManager       = userManager;
     _context           = context;
 }
Beispiel #3
0
        public async void TestSaveNewPost()
        {
            ///Test that you save
            DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("CreatePost").Options;

            using (GramDbContext context = new GramDbContext(options))
            {
                Post post = new Post();
                post.ID = 1;
                PostManager manager = new PostManager(context);
                await manager.SaveAsync(post);

                Post testPost = await context.Posts.FirstOrDefaultAsync(p => p.ID == post.ID);

                Assert.Equal(1, testPost.ID);
            }
        }
Beispiel #4
0
        public List <Comment> GetAllComments()
        {
            List <Comment> detalles = new List <Comment>();

            using (GramDbContext db = new GramDbContext())
            {
                try
                {
                    detalles = db.Comment.Include(x => x.User).Include(x => x.Foto).ToList();
                }
                catch (Exception e)
                {
                    e.ToString();
                }
            }
            return(detalles);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public async void TestPostCanFind()
        {
            ///Test that you can find a post
            DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("FindPost").Options;

            using (GramDbContext context = new GramDbContext(options))
            {
                Post        post    = new Post();
                PostManager manager = new PostManager(context);
                post.ID      = 3;
                post.Details = "Cray";
                await manager.SaveAsync(post);

                Post testPost = await manager.FindPost(post.ID);

                Assert.Equal(3, testPost.ID);
            }
        }
Beispiel #7
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);
        }
Beispiel #8
0
        public async void TestPostCanDelete()
        {
            ///Test that you can delete a post
            DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("DeletePost").Options;

            using (GramDbContext context = new GramDbContext(options))
            {
                Post        post    = new Post();
                PostManager manager = new PostManager(context);
                post.ID      = 4;
                post.Details = "Cray";
                post.Author  = "JTT";
                await manager.SaveAsync(post);

                await manager.DeleteAsync(post.ID);

                Assert.Null(await manager.FindPost(post.ID));
            }
        }
Beispiel #9
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);
        }
Beispiel #10
0
        public async void TestPostCanEdit()
        {
            ///Test that you can edit a post
            DbContextOptions <GramDbContext> options = new DbContextOptionsBuilder <GramDbContext>().UseInMemoryDatabase("EditPost").Options;

            using (GramDbContext context = new GramDbContext(options))
            {
                Post        post    = new Post();
                PostManager manager = new PostManager(context);
                post.ID      = 4;
                post.Details = "Cray";
                post.Author  = "JTT";
                await manager.SaveAsync(post);

                post.Details = "Changed cray";
                string expected = "Changed cray";
                Post   testPost = await manager.FindPost(post.ID);

                Assert.Equal(expected, testPost.Details);
            }
        }
Beispiel #11
0
        public bool IsFollow(string followId, string followedId)
        {
            using (GramDbContext db = new GramDbContext())
            {
                try
                {
                    Follows detalles = db
                                       .Follows
                                       .Where(x => x.ApplicationUserId == followId && x.Followed.ApplicationUserId == followedId)
                                       .Include(x => x.Followed)
                                       .FirstOrDefault();

                    if (detalles != null)
                    {
                        return(true);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(false);
        }
Beispiel #12
0
 public CommentManager(GramDbContext context)
 {
     _context = context;
 }
Beispiel #13
0
 public LikeRepository(GramDbContext context)
 {
     _context = context;
 }
Beispiel #14
0
 public CommentLikeRepository(GramDbContext context)
 {
     _context = context;
 }
 public ArchiveRepository(GramDbContext context)
 {
     _context = context;
 }
Beispiel #16
0
 public FotoRepositories(GramDbContext context, IHubContext <SignalRServer> _hubContext)
 {
     _context         = context;
     this._hubContext = _hubContext;
 }
Beispiel #17
0
 public NotificationRepository(GramDbContext context, IHubContext <SignalRServer> _hubContext)
 {
     _context         = context;
     this._hubContext = _hubContext;
 }
Beispiel #18
0
 public UserRepository(GramDbContext context, UserManager <ApplicationUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
Beispiel #19
0
 public PostManager(GramDbContext context)
 {
     _context = context;
 }