Exemplo n.º 1
0
 public bool AddOrUpdate(Comment comment)
 {
     try
     {
         using (var ctx = new MVCLabDataDbContext())
         {
             var commentToUpdate = ctx.Comments.Where(c => c.id == comment.id)
                                   .Include(c => c.Picture)
                                   .FirstOrDefault();
             if (commentToUpdate != null)
             {
                 commentToUpdate.Title      = comment.Title;
                 commentToUpdate.Body       = comment.Body;
                 commentToUpdate.DateEdited = comment.DateEdited;
                 ctx.SaveChanges();
                 return(true);
             }
             else
             {
                 ctx.Comments.Add(comment);
                 ctx.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception e)
     {
         //Handle exceptions
     }
     return(false);
 }
Exemplo n.º 2
0
        public bool AddOrUpdate(Gallery gallery)
        {
            try
            {
                using (var ctx = new MVCLabDataDbContext())
                {
                    var galleryToUpdate = ctx.Galleries.Where(g => g.id == gallery.id)
                                          .Include(g => g.Pictures)
                                          .FirstOrDefault();
                    if (galleryToUpdate != null)
                    {
                        galleryToUpdate.GalleryName = gallery.GalleryName;
                        ctx.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        var newGallery = new Gallery();
                        newGallery.User        = gallery.User;
                        newGallery.GalleryName = gallery.GalleryName;
                        newGallery.DateCreated = DateTime.Now;
                        newGallery.id          = gallery.id;
                        ctx.Galleries.Add(newGallery);
                        ctx.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                // handle exceptions
            }

            return(false);
        }
Exemplo n.º 3
0
 public IEnumerable <Comment> All()
 {
     using (var ctx = new MVCLabDataDbContext())
     {
         var comments = ctx.Comments
                        .Include(c => c.Picture);
         return(comments.ToList());
     }
 }
Exemplo n.º 4
0
 public IEnumerable <Picture> All()
 {
     using (var ctx = new MVCLabDataDbContext())
     {
         var pictures = ctx.Pictures
                        .Include(p => p.Comments)
                        .Include(p => p.Gallery);
         return(pictures.ToList());
     }
 }
Exemplo n.º 5
0
 public Gallery ByID(Guid id)
 {
     using (var ctx = new MVCLabDataDbContext())
     {
         var gallery = ctx.Galleries.Where(g => g.id == id)
                       .Include(g => g.Pictures)
                       .FirstOrDefault();
         return(gallery);
     }
 }
Exemplo n.º 6
0
        public IEnumerable <Gallery> All()
        {
            using (var ctx = new MVCLabDataDbContext())
            {
                var galleries = ctx.Galleries
                                .Include(g => g.Pictures);

                return(galleries.ToList());
            }
        }
Exemplo n.º 7
0
 public Comment ByID(Guid id)
 {
     using (var ctx = new MVCLabDataDbContext())
     {
         var comment = ctx.Comments.Where(c => c.id == id)
                       .Include(c => c.Picture)
                       .Include(c => c.Picture.User)
                       .FirstOrDefault();
         return(comment);
     }
 }
Exemplo n.º 8
0
 public Picture ByID(Guid id)
 {
     using (var ctx = new MVCLabDataDbContext())
     {
         var picture = ctx.Pictures.Where(p => p.id == id)
                       .Include(p => p.Comments)
                       .Include(p => p.Gallery)
                       .FirstOrDefault();
         return(picture);
     }
 }
Exemplo n.º 9
0
        public bool AddOrUpdate(Picture picture)
        {
            try
            {
                using (var ctx = new MVCLabDataDbContext())
                {
                    var pictureToUpdate = ctx.Pictures.Where(p => p.id == picture.id)
                                          .Include(p => p.Comments)
                                          .Include(p => p.Gallery)
                                          .FirstOrDefault();


                    if (pictureToUpdate != null)
                    {
                        pictureToUpdate.Name        = picture.Name;
                        pictureToUpdate.id          = picture.id;
                        pictureToUpdate.GalleryID   = picture.GalleryID;
                        pictureToUpdate.Path        = picture.Path;
                        pictureToUpdate.@public     = picture.@public;
                        pictureToUpdate.Description = picture.Description;
                        pictureToUpdate.DateEdited  = picture.DateEdited;
                        ctx.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        var newPicture = new Picture();
                        newPicture.Name        = picture.Name;
                        newPicture.id          = Guid.NewGuid();
                        newPicture.GalleryID   = picture.GalleryID;
                        newPicture.Path        = picture.Path;
                        newPicture.@public     = picture.@public;
                        newPicture.Description = picture.Description;
                        newPicture.DateEdited  = picture.DateEdited;
                        newPicture.DatePosted  = picture.DatePosted;
                        newPicture.User        = picture.User;
                        ctx.Pictures.Add(newPicture);
                        ctx.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                //Handle exceptions
            }
            return(false);
        }
Exemplo n.º 10
0
 public bool Delete(Guid id)
 {
     using (var ctx = new MVCLabDataDbContext())
     {
         var comment = ctx.Comments.Where(c => c.id == id)
                       .Include(c => c.Picture)
                       .FirstOrDefault();
         if (comment != null)
         {
             ctx.Comments.Remove(comment);
             ctx.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 11
0
 public ActionResult Delete(Guid commentID)
 {
     if (User.Identity.IsAuthenticated)
     {
         using (var ctx = new MVCLabDataDbContext())
         {
             var commentToRemove = repo.ByID(commentID);
             if (commentToRemove != null)
             {
                 repo.Delete(commentID);
             }
             return(Content("Comment was removed."));
         }
     }
     return(Content("Couldn't remove comment."));
 }
Exemplo n.º 12
0
 public bool Delete(Guid id)
 {
     using (var ctx = new MVCLabDataDbContext())
     {
         var picture = ctx.Pictures.Where(p => p.id == id)
                       .Include(p => p.Comments)
                       .Include(p => p.Gallery)
                       .FirstOrDefault();
         if (picture != null)
         {
             ctx.Pictures.Remove(picture);
             ctx.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 13
0
        public bool Delete(Guid id)
        {
            using (var ctx = new MVCLabDataDbContext())
            {
                var gallery = ctx.Galleries.FirstOrDefault(g => g.id == id);


                if (gallery != null)
                {
                    try
                    {
                        ctx.Galleries.Remove(gallery);
                        ctx.SaveChanges();
                        return(true);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                return(false);
            }
        }