示例#1
0
      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();
      }
示例#2
0
      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();
      }
示例#3
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();
      }