public void LetGroupViewComments(int userId, int groupId, int albumId, bool let) { //todo: add try-catch using (IUnitOfWork unitOfWork = WorkFactory.GetUnitOfWork()) { AvailableGroupModel availableGroup = GetAvailableGroup(userId, groupId, albumId, unitOfWork); availableGroup.CanSeeComments = let; unitOfWork.AvailableGroups.Update(availableGroup); unitOfWork.SaveChanges(); } }
protected override void Seed(DatabaseContext databaseContext) { //var random = new Random(); var cryptoProvider = new CryptoProvider(); var systemGroupList = new List <GroupModel>(); #region adminModel creation string adminSalt = cryptoProvider.GetNewSalt(); var adminModel = new UserModel { Email = "*****@*****.**", FirstName = ";)", LastName = ";)", Department = ";)", Albums = new Collection <AlbumModel>(), AuthInfos = new Collection <AuthInfoModel>(), Groups = new Collection <GroupModel>(), IsActivated = true, IsAdmin = true, Salt = adminSalt, UserPassword = cryptoProvider.CreateHashForPassword("qwerty", adminSalt) }; #endregion #region userModels creating var userModelsList = new List <UserModel>(); #region Artem Zagorodnuk string userSalt = cryptoProvider.GetNewSalt(); var user = new UserModel { Email = "*****@*****.**", FirstName = "Artem", LastName = "Zagorodnuk", Department = ".Net", Albums = new Collection <AlbumModel>(), AuthInfos = new Collection <AuthInfoModel>(), Groups = new Collection <GroupModel>(), IsActivated = true, IsAdmin = false, Salt = userSalt, UserPassword = cryptoProvider.CreateHashForPassword("qwerty", userSalt) }; userModelsList.Add(user); #endregion #region Anton Golovin userSalt = cryptoProvider.GetNewSalt(); user = new UserModel { Email = "*****@*****.**", FirstName = "Anton", LastName = "Golovin", Department = "Academy", Albums = new Collection <AlbumModel>(), AuthInfos = new Collection <AuthInfoModel>(), Groups = new Collection <GroupModel>(), IsActivated = true, IsAdmin = false, Salt = userSalt, UserPassword = cryptoProvider.CreateHashForPassword("qwerty", userSalt) }; userModelsList.Add(user); #endregion #region Andrey Spivakov userSalt = cryptoProvider.GetNewSalt(); user = new UserModel { Email = "*****@*****.**", FirstName = "Andrey", LastName = "Spivakov", Department = "Academy", Albums = new Collection <AlbumModel>(), AuthInfos = new Collection <AuthInfoModel>(), Groups = new Collection <GroupModel>(), IsActivated = true, IsAdmin = false, Salt = userSalt, UserPassword = cryptoProvider.CreateHashForPassword("qwerty", userSalt) }; userModelsList.Add(user); #endregion #region Александр Носов userSalt = cryptoProvider.GetNewSalt(); user = new UserModel { Email = "*****@*****.**", FirstName = "Александр", LastName = "Носов", Department = "Academy", Albums = new Collection <AlbumModel>(), AuthInfos = new Collection <AuthInfoModel>(), Groups = new Collection <GroupModel>(), IsActivated = true, IsAdmin = false, Salt = userSalt, UserPassword = cryptoProvider.CreateHashForPassword("qwerty", userSalt) }; userModelsList.Add(user); #endregion #region Mikhail Bratukha userSalt = cryptoProvider.GetNewSalt(); user = new UserModel { Email = "*****@*****.**", FirstName = "Mikhail", LastName = "Bratukha", Department = "Academy", Albums = new Collection <AlbumModel>(), AuthInfos = new Collection <AuthInfoModel>(), Groups = new Collection <GroupModel>(), IsActivated = true, IsAdmin = false, Salt = userSalt, UserPassword = cryptoProvider.CreateHashForPassword("qwerty", userSalt) }; userModelsList.Add(user); #endregion #region Oleg Beloy userSalt = cryptoProvider.GetNewSalt(); user = new UserModel { Email = "*****@*****.**", FirstName = "Oleg", LastName = "Beloy", Department = "Academy", Albums = new Collection <AlbumModel>(), AuthInfos = new Collection <AuthInfoModel>(), Groups = new Collection <GroupModel>(), IsActivated = true, IsAdmin = false, Salt = userSalt, UserPassword = cryptoProvider.CreateHashForPassword("qwerty", userSalt) }; userModelsList.Add(user); #endregion #region Alexander Towstonog userSalt = cryptoProvider.GetNewSalt(); user = new UserModel { Email = "*****@*****.**", FirstName = "Alexander", LastName = "Towstonog", Department = "Academy", Albums = new Collection <AlbumModel>(), AuthInfos = new Collection <AuthInfoModel>(), Groups = new Collection <GroupModel>(), IsActivated = true, IsAdmin = false, Salt = userSalt, UserPassword = cryptoProvider.CreateHashForPassword("qwerty", userSalt) }; userModelsList.Add(user); #endregion #endregion #region BlockedUsers var groupModel = new GroupModel() { GroupName = "BlockedUsers", Description = "System group. Not for use", OwnerId = -1, Users = new Collection <UserModel>() }; systemGroupList.Add(groupModel); #endregion var unitOfWorkFactory = new UnitOfWorkFactory(); using (IUnitOfWork unitOfWork = unitOfWorkFactory.GetUnitOfWork()) { // Admin account creating unitOfWork.Users.Add(adminModel); unitOfWork.SaveChanges(); // Users' acoount creating foreach (UserModel userModel in userModelsList) { unitOfWork.Users.Add(userModel); } unitOfWork.SaveChanges(); // Temporary album adding to each user (ever admin) List <UserModel> allUsersList = unitOfWork.Users.All().ToList(); foreach (UserModel userModel in allUsersList) { userModel.Albums.Add(new AlbumModel { Name = "Temporary", Description = "System album not for use", IsDeleted = false, Permissions = (int)AlbumModel.PermissionsMask.PublicAlbum, OwnerId = userModel.Id, Photos = new Collection <PhotoModel>(), Tags = new Collection <AlbumTagModel>(), AvailableGroups = new Collection <AvailableGroupModel>() }); unitOfWork.Users.Update(userModel); } unitOfWork.SaveChanges(); // Adding all system groups (Owner for all groups is Admin) var adminID = unitOfWork.Users.Find(a => a.Email == "*****@*****.**").Id; foreach (var systemGroup in systemGroupList) { systemGroup.OwnerId = adminID; unitOfWork.Groups.Add(systemGroup); } unitOfWork.SaveChanges(); #region adding test groups var group = new GroupModel { GroupName = "Test group", OwnerId = unitOfWork.Users.Find(a => a.Email == "*****@*****.**").Id, Description = "Test group" }; unitOfWork.Groups.Add(group); unitOfWork.SaveChanges(); #endregion #region adding album to user with lastname Towstonog UserModel maaak = unitOfWork.Users.Find(x => x.LastName == "Towstonog"); maaak.Albums.Add(new AlbumModel { Name = "First album", Description = "Default album by DBinit", IsDeleted = false, Permissions = (int)AlbumModel.PermissionsMask.PublicAlbum, OwnerId = maaak.Id, Tags = new Collection <AlbumTagModel>(), AvailableGroups = new Collection <AvailableGroupModel>(), Photos = new Collection <PhotoModel>() }); unitOfWork.Users.Update(maaak); unitOfWork.SaveChanges(); #endregion #region adding photos and group to album with name "First album" AlbumModel albumModel = unitOfWork.Albums.Find(album => album.Name == "First album"); var avialableGroup = new AvailableGroupModel { AlbumId = albumModel.Id, GroupId = 1, CanAddComments = true, CanAddPhotos = true, CanSeeComments = true, CanSeeLikes = true, CanSeePhotos = true }; albumModel.AvailableGroups.Add(avialableGroup); GeneratePhotos(albumModel, unitOfWork); #endregion #region adding album to user with lastname Golovin var golovinUser = unitOfWork.Users.Find(x => x.LastName == "Golovin"); var tags = new Collection <AlbumTagModel> { new AlbumTagModel { TagName = "tag" }, new AlbumTagModel { TagName = "tag1" }, new AlbumTagModel { TagName = "looooooooooooooooooong tag" } }; var albumForGolovin = new AlbumModel { Name = "Anton album", Description = "Default album by DBinit", IsDeleted = false, Permissions = (int)AlbumModel.PermissionsMask.PublicAlbum, OwnerId = golovinUser.Id, Tags = tags, AvailableGroups = new Collection <AvailableGroupModel>(), Photos = new Collection <PhotoModel>() }; var currentGroup = unitOfWork.Groups.Find(x => x.OwnerId == 1); golovinUser.Groups.Add(currentGroup); golovinUser.Albums.Add(albumForGolovin); unitOfWork.SaveChanges(); #endregion #region adding photos and group to album with name "Anton album" albumModel = unitOfWork.Albums.Find(album => album.Name == "Anton album"); avialableGroup = new AvailableGroupModel { AlbumId = albumModel.Id, GroupId = 1, CanAddComments = true, CanAddPhotos = true, CanSeeComments = true, CanSeeLikes = true, CanSeePhotos = true }; albumForGolovin.AvailableGroups.Add(avialableGroup); GeneratePhotos(albumModel, unitOfWork); #endregion } base.Seed(databaseContext); }