Esempio n. 1
0
 public void AddComment(Comment comment)
 {
     using (var ctx = new MVCLabbEntities())
     {
         comment.Id = Guid.NewGuid();
         ctx.Comments.Add(comment);
         ctx.SaveChanges();
     }
 }
Esempio n. 2
0
        public void AddAlbum(Album album)
        {
            using (var ctx = new MVCLabbEntities())
            {
                album.Id = Guid.NewGuid();
                ctx.Albums.Add(album);

                ctx.SaveChanges();
            }
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
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();
            }
        }
Esempio n. 6
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();
            }
        }
Esempio n. 7
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();
            }
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
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();
     }
 }
Esempio n. 10
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();
            }
        }