Exemplo n.º 1
0
 public List <Album> GettAllAlbums()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Albums.Include("User").Include("Photos").Include("Comments").ToList());
     }
 }
Exemplo n.º 2
0
 public Comment GetCommentByID(Guid id)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Comments.Include("User").Include("Photo").Include("Album").FirstOrDefault(x => x.Id == id));
     }
 }
Exemplo n.º 3
0
 public Photo GetPhotoFromDbById(Guid id)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Photos.Include("User").Include("Album").Include("Comments").FirstOrDefault(x => x.Id == id));
     }
 }
Exemplo n.º 4
0
 public Photo GetLastAddedPhoto()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Photos.Include("User").Include("Album").Include("Comments").OrderByDescending(x => x.Date).FirstOrDefault());
     }
 }
Exemplo n.º 5
0
 public List <Photo> GetPhotoFromDbByUserId(Guid userID)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Photos.Include("User").Include("Album").Include("Comments").Where(x => x.UserID == userID).ToList());
     }
 }
Exemplo n.º 6
0
 public List <Photo> GetAllPhotosFromDb()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Photos.Include("User").Include("Album").Include("Comments").ToList());
     }
 }
Exemplo n.º 7
0
 public List <Album> GettAllAlbumsByUserID(Guid userID)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Albums.Include("User").Include("Photos").Include("Comments").Where(x => x.User.Id == userID).ToList());
     }
 }
Exemplo n.º 8
0
        internal static bool LoginUser(string email, string password)
        {
            using (var dbCtx = new MVCLabbEntities())
            {
                foreach (var user in dbCtx.tbl_User)
                {
                    if (email == user.Email && UserHelper.GenerateSHA256Hash(password, user.Salt) == user.Password)
                    {
                        var identity = new ClaimsIdentity(new[] {
                            new Claim(ClaimTypes.Name, user.Name),
                            new Claim(ClaimTypes.Email, user.Email),
                            new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                            new Claim(ClaimTypes.Role, user.Admin ? "Admin" : "User")
                        },
                                                          "ApplicationCookie");

                        var ctx         = HttpContext.Current.Request.GetOwinContext();
                        var authManager = ctx.Authentication;

                        authManager.SignIn(identity);

                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 9
0
 public List <Comment> GetAllComentsByPhotoID(string id)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Comments.Include("User").Include("Photo").Include("Album").Where(x => x.PhotoID.ToString() == id).ToList());
     }
 }
Exemplo n.º 10
0
 public User GetUser(string id)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Users.Include("Photos").Include("Albums").Include("Comments").FirstOrDefault(x => x.Id.ToString() == id));
     }
 }
Exemplo n.º 11
0
 public List <Photo> GetAllPhotoesInAlbumByID(string id)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Photos.Include("User").Include("Album").Include("Comments").Where(x => x.AlbumID.ToString() == id).ToList());
     }
 }
Exemplo n.º 12
0
 public Album GetAlbumByID(Guid id)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Albums.Include("User").Include("Photos").Include("Comments").FirstOrDefault(x => x.Id == id));
     }
 }
Exemplo n.º 13
0
 public List <Comment> GetAllComments()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Comments.Include("User").Include("Photo").ToList());
     }
 }
Exemplo n.º 14
0
 public List <User> GetAllUsers()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Users.Include("Photos").Include("Albums").Include("Comments").ToList());
     }
 }
Exemplo n.º 15
0
 public List <Album> GetSearchAlbumsFromDB(string search)
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Albums.Include("User").Include("Photos").Include("Comments").Where(x =>
                                                                                       x.Name.Contains(search) || x.Description.Contains(search) || x.User.Name.Contains(search)).ToList());
     }
 }
Exemplo n.º 16
0
 public void AddComment(Comment comment)
 {
     using (var ctx = new MVCLabbEntities())
     {
         comment.Id = Guid.NewGuid();
         ctx.Comments.Add(comment);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 17
0
        public void AddAlbum(Album album)
        {
            using (var ctx = new MVCLabbEntities())
            {
                album.Id = Guid.NewGuid();
                ctx.Albums.Add(album);

                ctx.SaveChanges();
            }
        }
Exemplo n.º 18
0
        public void DeletePhotoFromDB(Photo model)
        {
            using (var ctx = new MVCLabbEntities())
            {
                var photoToDelete = ctx.Photos.FirstOrDefault(x => x.Id == model.Id);
                ctx.Photos.Remove(photoToDelete);

                ctx.SaveChanges();
            }
        }
Exemplo n.º 19
0
        public void AddPhotoToDB(Photo photoToDB)
        {
            photoToDB.AlbumID = photoToDB.AlbumID == Guid.Empty ? null : photoToDB.AlbumID;

            using (var ctx = new MVCLabbEntities())
            {
                ctx.Photos.Add(photoToDB);

                ctx.SaveChanges();
            }
        }
Exemplo n.º 20
0
        public void DeleteAlbum(Album album)
        {
            using (var ctx = new MVCLabbEntities())
            {
                var albumDB = ctx.Albums.FirstOrDefault(x => x.Id == album.Id);

                ctx.Albums.Remove(albumDB);

                ctx.SaveChanges();
            }
        }
Exemplo n.º 21
0
        public void DeleteComment(Comment comment)
        {
            using (var ctx = new MVCLabbEntities())
            {
                var commentDB = ctx.Comments.FirstOrDefault(x => x.Id == comment.Id);
                ctx.Comments.Remove(commentDB);


                ctx.SaveChanges();
            }
        }
Exemplo n.º 22
0
        public void AddUser(User user)
        {
            user.Salt     = CreateSalt(10);
            user.Password = GenerateSHA256Hash(user.Password, user.Salt);

            using (var ctx = new MVCLabbEntities())
            {
                ctx.Users.Add(user);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 23
0
 public void UdaptePhoto(Photo photo)
 {
     photo.AlbumID = photo.AlbumID == Guid.Empty ? null : photo.AlbumID;
     using (var ctx = new MVCLabbEntities())
     {
         var photoFromDb = ctx.Photos.FirstOrDefault(x => x.Id == photo.Id);
         photoFromDb.Name        = photo.Name;
         photoFromDb.Description = photo.Description;
         photoFromDb.AlbumID     = photo.AlbumID;
         ctx.SaveChanges();
     }
 }
Exemplo n.º 24
0
        public void UpdateAlbum(Album album)
        {
            using (var ctx = new MVCLabbEntities())
            {
                var albumDB = ctx.Albums.FirstOrDefault(x => x.Id == album.Id);

                albumDB.Name        = album.Name;
                albumDB.Description = album.Description;

                ctx.SaveChanges();
            }
        }
Exemplo n.º 25
0
        public User ValidateLogin(string email, string password)
        {
            using (var dbCtx = new MVCLabbEntities())
            {
                foreach (var user in dbCtx.Users)
                {
                    if (email == user.Email && GenerateSHA256Hash(password, user.Salt) == user.Password)
                    {
                        return(user);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 26
0
        public void UpdateUser(User user)
        {
            using (var ctx = new MVCLabbEntities())
            {
                User userFromDB = ctx.Users.Where(x => x.Id == user.Id).FirstOrDefault();
                userFromDB.Name    = user.Name;
                userFromDB.Country = user.Country;
                userFromDB.Email   = user.Email;

                if (userFromDB.Password != user.Password)
                {
                    var salt     = CreateSalt(10);
                    var password = GenerateSHA256Hash(user.Password, salt);

                    userFromDB.Salt     = salt;
                    userFromDB.Password = password;
                }

                ctx.SaveChanges();
            }
        }