Пример #1
0
        public AlbumEntityModel GetAlbum(int id)
        {
            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                /*
                 *  the error with the disposed thingy is because i missed including the user (lazy loading)
                 *  which caused the app to crash, because when i try to access user properties later on, the user
                 *  for an album is not loaded, and the connection is closed by then
                 */
                AlbumEntityModel entity = cx.Albums
                                          .Where(a => a.Id == id)
                                          .Include(a => a.Photos)
                                          .Include(a => a.Comments)
                                          .Include(a => a.User)
                                          .FirstOrDefault();

                return(entity);
            }


            //using (PhotoExplorerEntities _context = new PhotoExplorerEntities())
            //{
            //    UserEntityModel user = _context.Users
            //        .Where(u => u.Id == IserModelId)
            //        .Include(u => u.Albums
            //            .Select(p => p.Photos
            //            .Select(c => c.Comments))) //neccessary to include the albums
            //        .FirstOrDefault();
            //    return user;
            //}
        }
        public ActionResult PhotoCreate(PhotoUploadViewModel model, HttpPostedFileBase[] photofiles, AlbumListedViewModel albumidmodel /*albumid*/)
        {
            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                AlbumEntityModel entity = cx.Albums.FirstOrDefault(a => a.Id == albumidmodel.Id);

                foreach (var file in photofiles)
                {
                    //Create new photo entity foreach file that gets uploaded through the UI
                    PhotoEntityModel uploadedPhoto = new PhotoEntityModel()
                    {
                        Name        = model.Name,
                        FileName    = file.FileName,
                        Description = model.Description,
                    };


                    //save physical file representation of photo
                    file.SaveAs(Server.MapPath($"~/photos/{uploadedPhoto.FileName}"));

                    //save class object representation of photo into album we are currently in
                    entity.Photos.Add(uploadedPhoto);

                    //persist/save to database
                    cx.SaveChanges();
                }
            }

            System.Threading.Thread.Sleep(800);//simulate waiting time

            return(RedirectToAction("Dashboard", "Account"));
        }
Пример #3
0
 public static Album MapAlbumModel(AlbumEntityModel album)
 {
     return(new Album
     {
         AlbumID = album.AlbumId,
         AlbumName = album.AlbumName,
         AlbumComment = album.Comment.Select(x => CommentsModelMapper.ModelToEntity(x)).ToList()
     });
 }
Пример #4
0
        public static Album ModelToEntity(AlbumEntityModel entityModel)
        {
            var model = new Album();

            model.AlbumID       = entityModel.AlbumId;
            model.AlbumName     = entityModel.AlbumName;
            model.AlbumComments = MapCommentModel(entityModel.Comment);
            return(model);
        }
Пример #5
0
        public static AlbumEntityModel EntityToModel(Album albummodel)
        {
            AlbumEntityModel aEntity = new AlbumEntityModel();

            aEntity.AlbumId   = albummodel.AlbumID;
            aEntity.AlbumName = albummodel.AlbumName;
            aEntity.Comment   = MapCommentEntityModel(albummodel.AlbumComments);
            return(aEntity);
        }
Пример #6
0
        public static AlbumEntityModel EntityToModel(Album albumModel)
        {
            AlbumEntityModel entity = new AlbumEntityModel();

            entity.AlbumId   = albumModel.AlbumID;
            entity.AlbumName = albumModel.AlbumName;
            //entity.Photo = MapPhotoEntityModel(albumModel.Photos);
            entity.Comment = MapCommentsEntityModel(albumModel.AlbumComment);
            return(entity);
        }
Пример #7
0
 public void DeleteAlbum(AlbumEntityModel album)
 {
     using (var context = new MvcDataContext())
     {
         var deleteAlbum =
             context.AlbumEntityModels.Include("Comment").FirstOrDefault(x => x.AlbumId == album.AlbumId);
         context.AlbumEntityModels.Remove(deleteAlbum);
         context.AlbumEntityModels.AddOrUpdate(deleteAlbum);
         context.SaveChanges();
     }
 }
Пример #8
0
 public void AddAlbum(AlbumEntityModel newalbum)
 {
     using (var context = new MvcDataContext())
     {
         AlbumEntityModel album = new AlbumEntityModel();
         album.AlbumId   = newalbum.AlbumId;
         album.AlbumName = newalbum.AlbumName;
         album.Comment   = newalbum.Comment;
         context.AlbumEntityModels.Add(album);
         context.AlbumEntityModels.AddOrUpdate(album);
         context.SaveChanges();
     }
 }
Пример #9
0
 public void AddNewAlbum(AlbumEntityModel newalbum)
 {
     using (var context = new MVCLabbRepositoryDbContext())
     {
         AlbumEntityModel album = new AlbumEntityModel();
         album.AlbumId   = newalbum.AlbumId;
         album.AlbumName = newalbum.AlbumName;
         album.Comment   = newalbum.Comment;
         //album.Photo = newalbum.Photo;
         context.AlbumEntityModels.Add(album);
         context.AlbumEntityModels.AddOrUpdate(album);
         context.SaveChanges();
     }
 }
Пример #10
0
        public static AlbumDetailsViewModel EntityToModel(AlbumEntityModel entity)
        {
            AlbumDetailsViewModel model = new AlbumDetailsViewModel()
            {
                Id          = entity.Id,
                Name        = entity.Name,
                Comments    = entity.Comments,
                DateCreated = entity.DateCreated,
                Description = entity.Description,
                Photos      = entity.Photos,
                User        = entity.User,
            };

            return(model);
        }
Пример #11
0
        public void CreateAlbum(int userid, string albumName, string albumDescription)
        {
            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                AlbumEntityModel newEntityAlbum = new AlbumEntityModel()
                {
                    Name        = albumName,
                    Description = albumDescription,
                };

                var userEntity = cx.Users.FirstOrDefault(u => u.Id == userid);

                userEntity.Albums.Add(newEntityAlbum);

                cx.SaveChanges();
            }
        }
Пример #12
0
        public AlbumEntityModel Add(AlbumEntityModel newAlbum, int userId)
        {
            using (PhotoExplorerEntities _context = new PhotoExplorerEntities())
            {
                //get the owner of the album
                var albumUser = _context.Users.Where(u => u.Id == userId)
                                .FirstOrDefault();

                //set some properties of the new album
                //newAlbum.AlbumId = Guid.NewGuid();
                newAlbum.DateCreated = DateTime.Now;
                newAlbum.Photos      = new List <PhotoEntityModel>();
                newAlbum.User        = albumUser;
                newAlbum.Comments    = new List <CommentEntityModel>();

                //add the album to the users albums
                albumUser.Albums.Add(newAlbum);
                //_context.Albums.Add(newAlbum);

                _context.SaveChanges();

                return(newAlbum);
            }
        }
Пример #13
0
        public ActionResult AlbumCreate(AlbumCreateViewModel model)
        {
            ClaimsIdentity currentIdentity = User.Identity as ClaimsIdentity;
            int            userid          = int.Parse(currentIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);

            using (PhotoExplorerEntities cx = new PhotoExplorerEntities())
            {
                AlbumEntityModel newEntityAlbum = new AlbumEntityModel()
                {
                    Name        = model.Name,
                    Description = model.Description,
                };

                var userEntity = cx.Users.FirstOrDefault(u => u.Id == userid);

                userEntity.Albums.Add(newEntityAlbum);

                cx.SaveChanges();
            }

            System.Threading.Thread.Sleep(500);//simulate waiting time

            return(RedirectToAction("Dashboard", "Account"));
        }
Пример #14
0
        private void Seed()
        {
            /*
             *  due to us not adding the user,album and comments properties to the instantiation
             *  of the photoentities, we cannot include them later on for the photos when retrieving them
             *  int he photodetails action in contentmanagementcontroller. we have to get the specific
             *  photo by going through the users and their albums, and then the photos.
             */
            #region user 1
            PhotoEntityModel p1 = new PhotoEntityModel()
            {
                FileName    = "event1.jpg",
                Name        = "first event",
                DateCreated = DateTime.Now,
                Description = "no description",
            };
            PhotoEntityModel p2 = new PhotoEntityModel()
            {
                FileName    = "event2.jpg",
                Name        = "second event",
                DateCreated = DateTime.Now,
                Description = "no description",
            };
            PhotoEntityModel p3 = new PhotoEntityModel()
            {
                FileName    = "event3.jpg",
                Name        = "third event",
                DateCreated = DateTime.Now,
                Description = "no description",
            };

            AlbumEntityModel a1 = new AlbumEntityModel()
            {
                Name        = "my coding events",
                Description = "coding events that i have attended",
                DateCreated = DateTime.Now,
                Comments    = new List <CommentEntityModel>(),
                Photos      = new List <PhotoEntityModel>()
                {
                    p1, p2, p3
                },
            };

            UserEntityModel u1 = new UserEntityModel()
            {
                Fullname       = "Ivan Prgomet",
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                DateRegistered = DateTime.Now,
                Albums         = new List <AlbumEntityModel>()
                {
                    a1
                },
            };
            #endregion

            #region user 2
            PhotoEntityModel p4 = new PhotoEntityModel()
            {
                FileName    = "code1.jpg",
                Name        = "some code",
                DateCreated = DateTime.Now,
                Description = "no description",
            };
            AlbumEntityModel a2 = new AlbumEntityModel()
            {
                Name        = "random coding photos",
                Description = "just some coding casual coding photos",
                DateCreated = DateTime.Now,
                Comments    = new List <CommentEntityModel>(),
                Photos      = new List <PhotoEntityModel>()
                {
                    p4
                },
            };

            UserEntityModel u2 = new UserEntityModel()
            {
                Fullname       = "lea winchester",
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                DateRegistered = DateTime.Now,
                Albums         = new List <AlbumEntityModel>()
                {
                    a2
                },
            };
            #endregion

            #region user 3
            PhotoEntityModel p5 = new PhotoEntityModel()
            {
                FileName    = "mockerie1.jpg",
                Name        = "mock one",
                DateCreated = DateTime.Now,
                Description = "no description",
            };
            PhotoEntityModel p6 = new PhotoEntityModel()
            {
                FileName    = "mockerie2.jpg",
                Name        = "mock two",
                DateCreated = DateTime.Now,
                Description = "no description",
            };
            PhotoEntityModel p7 = new PhotoEntityModel()
            {
                FileName    = "mockerie3.jpg",
                Name        = "mock three",
                DateCreated = DateTime.Now,
                Description = "no description",
            };
            PhotoEntityModel p8 = new PhotoEntityModel()
            {
                FileName    = "mockerie4.jpg",
                Name        = "mock four",
                DateCreated = DateTime.Now,
                Description = "no description",
            };
            AlbumEntityModel a3 = new AlbumEntityModel()
            {
                Name        = "mockups",
                Description = "some of my experimental mockups",
                DateCreated = DateTime.Now,
                Comments    = new List <CommentEntityModel>(),
                Photos      = new List <PhotoEntityModel>()
                {
                    p5, p6, p7, p8
                },
            };

            UserEntityModel u3 = new UserEntityModel()
            {
                Fullname       = "jason bourne",
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                DateRegistered = DateTime.Now,
                Albums         = new List <AlbumEntityModel>()
                {
                    a3
                },
            };
            #endregion
            using (PhotoExplorerEntities context = new PhotoExplorerEntities())
            {
                context.Users.AddRange(new List <UserEntityModel> {
                    u1, u2, u3
                });

                context.SaveChanges();
            }
        }