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); }
public HomeController( IFotoRepository fotoRepository, ICommentRepository commentRepository, IUserRepository userRepository, UserManager <ApplicationUser> userManager, GramDbContext context ) { _fotoRepository = fotoRepository; _commentRepository = commentRepository; _userRepository = userRepository; _userManager = userManager; _context = context; }
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); } }
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); }
//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); }
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); } }
//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); }
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)); } }
//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); }
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); } }
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); }
public CommentManager(GramDbContext context) { _context = context; }
public LikeRepository(GramDbContext context) { _context = context; }
public CommentLikeRepository(GramDbContext context) { _context = context; }
public ArchiveRepository(GramDbContext context) { _context = context; }
public FotoRepositories(GramDbContext context, IHubContext <SignalRServer> _hubContext) { _context = context; this._hubContext = _hubContext; }
public NotificationRepository(GramDbContext context, IHubContext <SignalRServer> _hubContext) { _context = context; this._hubContext = _hubContext; }
public UserRepository(GramDbContext context, UserManager <ApplicationUser> userManager) { _context = context; _userManager = userManager; }
public PostManager(GramDbContext context) { _context = context; }