public ActionResult Edit(Guid id) { AlbumDto album = readModel.GetAlbums().FirstOrDefault(a => a.Id == id); UserDto user = (UserDto)Session["user"]; PrivacyViewModel pr = new PrivacyViewModel(); pr.Level = album.Privacy.Level; pr.GroupNames = user.Groups.Select(g => new SelectListItem() { Text = g.Name, Value = g.Id.ToString(), Selected = album.Privacy.Level == PrivacyLevel.Group ? ((ImageHoster.CQRS.ReadModel.Dto.GroupPrivacy)(album.Privacy)).GroupsEligible.FirstOrDefault(group => g.Id == group.Id) != null : false }); pr.OnlyLoggedInUsers = album.Privacy.OnlyLoggedIn; pr.Publish = album.Privacy.Publicized; if (user.Equals(album.Owner)) { EditAlbumViewModel model = new EditAlbumViewModel() { Id = id, Description = album.Description, Title = album.Title, Privacy = pr }; return View(model); } else { return new HttpUnauthorizedResult(); } }
public ActionResult Edit(EditAlbumViewModel model) { AlbumDto album = readModel.GetAlbums().FirstOrDefault(a => a.Id == model.Id); UserDto user = (UserDto)Session["user"]; if (user == null) return new HttpUnauthorizedResult(); if (album == null) return new HttpNotFoundResult(); bus.Send(new EditAlbumInfo() { Id = Guid.NewGuid(), User = user.Id, AlbumId = album.Id, Description = model.Description, Title = model.Title, Privacy = new Privacy() { OwnerId = user.Id, VisibleToGroups = model.Privacy.SelectedGroups ?? new List<Guid>(), Published = model.Privacy.Publish, OnlyForLoggedInUsers = model.Privacy.OnlyLoggedInUsers, Level = model.Privacy.Level }, Bus = bus, OldPrivacy = new Privacy() { OwnerId = album.Owner.Id, VisibleToGroups = album.Privacy is ImageHoster.CQRS.ReadModel.Dto.GroupPrivacy ? ((ImageHoster.CQRS.ReadModel.Dto.GroupPrivacy)album.Privacy).GroupsEligible.Select(g => g.Id) : new List<Guid>(), Published = album.Privacy.Publicized, OnlyForLoggedInUsers = album.Privacy.OnlyLoggedIn, Level = album.Privacy.Level }, PhotoPrivacies = album.Photos.ToDictionary(p => p.Id, p => new Privacy() { OwnerId = p.UploadedBy.Id, VisibleToGroups = p.Privacy is ImageHoster.CQRS.ReadModel.Dto.GroupPrivacy ? ((ImageHoster.CQRS.ReadModel.Dto.GroupPrivacy)p.Privacy).GroupsEligible.Select(g => g.Id) : new List<Guid>(), Published = p.Privacy.Publicized, OnlyForLoggedInUsers = p.Privacy.OnlyLoggedIn, Level = p.Privacy.Level }) }); return RedirectToAction("Album", new { id = album.Id }); }