public ActionResult AlbumDetails(int id) { AlbumDetailsViewModel model = EFMapper.EntityToModel(albumRepo.GetAlbum(id)); #region notused //AlbumDetailsViewModel model = null; //using (PhotoExplorerEntities cx = new PhotoExplorerEntities()) //{ // var entity = cx.Albums // .Include(a => a.Photos) // .Include(a => a.Comments) // .FirstOrDefault(a => a.Id == id); // model = new AlbumDetailsViewModel() // { // Id = entity.Id, // Name = entity.Name, // Comments = entity.Comments, // DateCreated = entity.DateCreated, // Description = entity.Description, // Photos = entity.Photos, // User = entity.User, // }; //} #endregion return(View(model)); }
public ActionResult Index() { #region retrieving the claim values for the currently logged in user (to retrieve him using his/her id) ClaimsIdentity currentIdentity = User.Identity as ClaimsIdentity; string modelfullname = (currentIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)).ToString(); //not used string modelusername = (currentIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.GivenName)).ToString(); //not used var modelid = int.Parse((currentIdentity.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)).Value); #endregion UserDetailsViewModel model = EFMapper.EntityToModel(userRepo.GetUser(modelid)); #region notused //UserDetailsViewModel model = null; //using (PhotoExplorerEntities cx = new PhotoExplorerEntities()) //{ // UserEntityModel entity = cx.Users.FirstOrDefault(u => u.Id == modelid); // #region mapping necessary properties from entitymodel to the viewmodel // model = new UserDetailsViewModel() // { // Id = entity.Id, // Username = entity.Username, // Fullname = entity.Fullname, // Albums = entity.Albums, // DateRegistered = entity.DateRegistered, // Email = entity.Email, // }; // #endregion //} #endregion return(View(model)); }
public ActionResult Details(int Id) { PhotoDetailsViewModel model = EFMapper.EntityToModel(photoRepo.GetPhoto(Id)); using (PhotoExplorerEntities cx = new PhotoExplorerEntities()) { foreach (var user in cx.Users) { foreach (var album in user.Albums) { foreach (var photo in album.Photos) { if (photo.Id == Id) { model.User = user; break; } } } } } #region notused ////todo: retrieve this photos uploader //#region retrieve photo to show //PhotoDetailsViewModel model = null; //using (PhotoExplorerEntities cx = new PhotoExplorerEntities()) //{ // PhotoEntityModel entity = cx.Photos // .Where(p => p.Id == Id) // .FirstOrDefault(); // ///todo: make this more effective.. // #region retrieve uploader of photoentity // UserEntityModel photoOwnerEntity = null; // foreach (var user in cx.Users) // { // foreach (var album in user.Albums) // { // foreach (var photo in album.Photos) // { // if (photo.Id == Id) // { // photoOwnerEntity = user; // break; // } // } // } // } // #endregion // model = new PhotoDetailsViewModel() // { // Id = entity.Id, // Name = entity.Name, // FileName = entity.FileName, // DateCreated = entity.DateCreated, // DateChanged = entity.DateChanged, // Album = entity.Album, // Comments = entity.Comments, //due to us already having the model collection initialized in the photodetailsviewmodel class, we only have to transfer the collection VALUES from the entity collection to the model collection. // Description = entity.Description, // User = photoOwnerEntity, // }; //} //#endregion #endregion return(View("Details", model)); }