public void Save(TadmapImage image) { bool isNew = false; TadmapDb db = new TadmapDb(); UserImage dbImage = db.UserImages.SingleOrDefault(i => i.Id == image.Id); if (dbImage == null) { dbImage = new UserImage(); // can't change date added, id or owner dbImage.DateAdded = DateTime.Now; dbImage.UserId = image.UserId; dbImage.Id = image.Id; isNew = true; } else { isNew = false; } dbImage.Title = image.Title; dbImage.Description = image.Description; dbImage.Key = image.Key; dbImage.OffensiveCount = image.IsOffensive ? (byte)1 : (byte)0; dbImage.Privacy = image.IsPublic ? (byte)1 : (byte)0; if (isNew) db.UserImages.InsertOnSubmit(dbImage); db.SubmitChanges(); }
public void Save(Model.User.User user) { bool isNew = false; TadmapDb db = new TadmapDb(ConnectionString); User dbUser = db.Users.SingleOrDefault(i => i.Id == user.Id); if (dbUser == null) { dbUser = new User(); dbUser.Name = user.Name; var roles = user.Roles.Select(r => new UserRole { Role = r }); dbUser.UserRoles.AddRange(roles); var openIds = user.OpenIds.Select(id => new OpenId { OpenIdUrl = id }); dbUser.OpenIds.AddRange(openIds); isNew = true; } else { isNew = false; } if (isNew) db.Users.InsertOnSubmit(dbUser); db.SubmitChanges(); }
public IQueryable<Model.User.User> GetAllUsers() { TadmapDb db = new TadmapDb(ConnectionString); return from i in db.Users select new Model.User.User { Id = i.Id, OpenIds = i.OpenIds.Select(id => id.OpenIdUrl).ToList(), Roles = i.UserRoles.Select(role => role.Role).ToList() }; }
public IQueryable<TadmapImage> GetAllImages(IBinaryRepository binaryRepository) { TadmapDb db = new TadmapDb(); return from i in db.UserImages select new TadmapImage(binaryRepository) { Id = i.Id, Title = i.Title, Description = i.Description, Key = i.Key, IsPublic = i.Privacy == 1, IsOffensive = i.OffensiveCount > 0, OwnerName = i.User.UserOpenIds.Single().OpenIdUrl, ImageSet = new ImageSet1(i.Key) }; }
public IQueryable<TadmapImage> GetAllImages() { var db = new TadmapDb(ConnectionString); return from i in db.Images select new TadmapImage { Id = i.Id, Title = i.Title, Description = i.Description, Key = i.Key, IsPublic = i.Privacy == 1, IsOffensive = i.OffensiveCount > 0, OwnerName = i.User.OpenIds.Single().OpenIdUrl, ImageSet = new ImageSet1(i.Key), UserId = i.User.Id, HasIcon = i.ThumbnailAvailable, ZoomLevel = i.ZoomLevels ?? 0, TileSize = i.TileSize ?? 0 }; }
public void Save(TadmapImage image) { bool isNew = false; TadmapDb db = new TadmapDb(ConnectionString); Image dbImage = db.Images.SingleOrDefault(i => i.Id == image.Id); if (dbImage == null) { dbImage = new Image(); // can't change date added, id or owner dbImage.DateAdded = DateTime.Now; dbImage.UserId = image.UserId; isNew = true; } else { isNew = false; } dbImage.Title = image.Title; dbImage.Description = image.Description; dbImage.Key = image.Key; dbImage.OffensiveCount = image.IsOffensive ? (byte)1 : (byte)0; dbImage.Privacy = image.IsPublic ? (byte)1 : (byte)0; dbImage.TileSize = image.TileSize; dbImage.ZoomLevels = image.ZoomLevel > 0 ? new int?(image.ZoomLevel) : null; dbImage.ThumbnailAvailable = image.HasIcon; if (isNew) db.Images.InsertOnSubmit(dbImage); db.SubmitChanges(); }