Beispiel #1
0
        public static Comments ModelToEntity(CommentEntityModel comments)
        {
            Comments model = new Comments();

            model.Id = comments.Id;
            model.CommentOnPicture = comments.CommentPhoto;
            model.CommentOnAlbum   = comments.CommentAlbum;
            return(model);
        }
Beispiel #2
0
        public static CommentEntityModel EntityToModel(Comments comments)
        {
            CommentEntityModel cEntity = new CommentEntityModel();

            cEntity.Id           = comments.Id;
            cEntity.CommentPhoto = comments.CommentOnPicture;
            cEntity.CommentAlbum = comments.CommentOnAlbum;
            return(cEntity);
        }
Beispiel #3
0
 public static Comments MapCommentModel(CommentEntityModel comments)
 {
     return(new Comments
     {
         Id = comments.Id,
         CommentOnPicture = comments.CommentPhoto,
         CommentOnAlbum = comments.CommentAlbum
     });
 }
 public void AddNewAlbumComment(Guid albumid, CommentEntityModel newalbumComment)
 {
     using (var context = new MvcDataContext())
     {
         var albumEnt = context.AlbumEntityModels.FirstOrDefault(x => x.AlbumId == albumid);
         albumEnt.Comment.Add(newalbumComment);
         context.AlbumEntityModels.AddOrUpdate(albumEnt);
         context.SaveChanges();
     }
 }
 public void AddNewPhotoComment(Guid photoid, CommentEntityModel newphotoComment)
 {
     using (var context = new MvcDataContext())
     {
         var photoEnt = context.PhotoEntityModels.FirstOrDefault(x => x.PhotoId == photoid);
         photoEnt.Comment.Add(newphotoComment);
         context.PhotoEntityModels.AddOrUpdate(photoEnt);
         context.SaveChanges();
     }
 }
Beispiel #6
0
        public void NewAlbumComment(int albumid, CommentEntityModel newAlbumComment)
        {
            using (PhotoExplorerEntities _context = new PhotoExplorerEntities())
            {
                var albumEntity = _context.Albums.FirstOrDefault(a => a.Id == albumid);

                albumEntity.Comments.Add(newAlbumComment);

                _context.SaveChanges();
            }
        }
Beispiel #7
0
        public static CommentEntityModel ModelToEntity(CommentViewModel model)
        {
            var entity = new CommentEntityModel();

            entity.Comment    = model.Comment;
            entity.id         = model.id;
            entity.PictureID  = model.PictureID;
            entity.UserID     = model.UserID;
            entity.Title      = model.Title;
            entity.DateEdited = model.DateEdited;
            entity.DatePosted = model.DatePosted;

            return(entity);
        }
Beispiel #8
0
        public ActionResult Comment(int id, string txt_comment)
        {
            PhotoDetailsViewModel model = null;

            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                // retrieve currently logged in user
                ClaimsIdentity  currentIdentity = User.Identity as ClaimsIdentity;
                int             userid          = int.Parse(currentIdentity.Claims.FirstOrDefault(u => u.Type == ClaimTypes.NameIdentifier).Value);
                UserEntityModel loggedInEntity  = cx.Users.FirstOrDefault(u => u.Id == userid);

                // initialize new comment entity
                CommentEntityModel commentModel = new CommentEntityModel()
                {
                    DateCreated = DateTime.Now,
                    Comment     = txt_comment,
                    Commenter   = loggedInEntity.Username,
                };

                // retrieve the photo entity commented on
                PhotoEntityModel entity = cx.Photos
                                          .Where(p => p.Id == id)
                                          .FirstOrDefault();

                entity.Comments.Add(commentModel);

                cx.SaveChanges();

                //mapping
                model = new PhotoDetailsViewModel()
                {
                    Name        = entity.Name,
                    Album       = entity.Album,
                    DateCreated = entity.DateCreated,
                    FileName    = entity.FileName,
                    Description = entity.Description,
                    Id          = entity.Id,
                    User        = loggedInEntity,
                    Comments    = entity.Comments,
                };
            }

            /*
             *  note: only updating portion of the page by using partial view (with the NEW model)
             */
            return(PartialView("_PhotoComments", model));
        }
Beispiel #9
0
        public static CommentViewModel EntityToModel(CommentEntityModel entity)
        {
            var model = new CommentViewModel();

            model.Comment    = entity.Comment;
            model.id         = entity.id;
            model.PictureID  = entity.PictureID;
            model.Picture    = EntityToModel(entity.Picture);
            model.UserID     = entity.UserID;
            model.User       = EntityToModel(entity.User);
            model.Title      = entity.Title;
            model.DateEdited = entity.DateEdited;
            model.DatePosted = entity.DatePosted;



            return(model);
        }
 public bool AddOrUpdate(CommentEntityModel comment)
 {
     try
     {
         using (var ctx = new DataContext())
         {
             var commentToUpdate = ctx.Comments.Where(c => c.id == comment.id)
                                   .Include(c => c.User)
                                   .Include(c => c.Picture)
                                   .FirstOrDefault();
             if (commentToUpdate != null)
             {
                 commentToUpdate.Title      = comment.Title;
                 commentToUpdate.Comment    = comment.Comment;
                 commentToUpdate.DateEdited = comment.DateEdited;
                 ctx.SaveChanges();
                 return(true);
             }
             else
             {
                 var newComment = new CommentEntityModel();
                 newComment.Title      = comment.Title;
                 newComment.Comment    = comment.Comment;
                 newComment.DatePosted = comment.DatePosted;
                 newComment.DateEdited = comment.DateEdited;
                 newComment.UserID     = comment.UserID;
                 newComment.PictureID  = comment.PictureID;
                 ctx.Comments.Add(newComment);
                 ctx.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception e)
     {
         //Handle exceptions
     }
     return(false);
 }