Beispiel #1
0
 public List <Album> GettAllAlbums()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Albums.Include("User").Include("Photos").Include("Comments").ToList());
     }
 }
Beispiel #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));
     }
 }
Beispiel #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));
     }
 }
Beispiel #4
0
 public Photo GetLastAddedPhoto()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Photos.Include("User").Include("Album").Include("Comments").OrderByDescending(x => x.Date).FirstOrDefault());
     }
 }
Beispiel #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());
     }
 }
Beispiel #6
0
 public List <Photo> GetAllPhotosFromDb()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Photos.Include("User").Include("Album").Include("Comments").ToList());
     }
 }
Beispiel #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());
     }
 }
Beispiel #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);
        }
Beispiel #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());
     }
 }
Beispiel #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));
     }
 }
Beispiel #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());
     }
 }
Beispiel #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));
     }
 }
Beispiel #13
0
 public List <Comment> GetAllComments()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Comments.Include("User").Include("Photo").ToList());
     }
 }
Beispiel #14
0
 public List <User> GetAllUsers()
 {
     using (var ctx = new MVCLabbEntities())
     {
         return(ctx.Users.Include("Photos").Include("Albums").Include("Comments").ToList());
     }
 }
Beispiel #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());
     }
 }
Beispiel #16
0
 public void AddComment(Comment comment)
 {
     using (var ctx = new MVCLabbEntities())
     {
         comment.Id = Guid.NewGuid();
         ctx.Comments.Add(comment);
         ctx.SaveChanges();
     }
 }
Beispiel #17
0
        public void AddAlbum(Album album)
        {
            using (var ctx = new MVCLabbEntities())
            {
                album.Id = Guid.NewGuid();
                ctx.Albums.Add(album);

                ctx.SaveChanges();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
     }
 }
Beispiel #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();
            }
        }
Beispiel #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);
        }
Beispiel #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();
            }
        }