예제 #1
0
        public static void AddUser(User user)
        {
            var entity = new ImageNetworkEntities();

            entity.User.Add(user);
            entity.SaveChanges();
        }
 partial void DeleteUser(User instance);
 partial void UpdateUser(User instance);
 partial void InsertUser(User instance);
예제 #5
0
        public static void Rate(User user, Image image, int rating)
        {
            var entity = new ImageNetworkEntities();

            var userImageRating = entity.UserImageRating.FirstOrDefault(a => a.UserId == user.Id && a.ImageId == image.Id);
            if (userImageRating != null)
            {
                if (userImageRating.Rating == rating)
                {
                    entity.UserImageRating.Remove(userImageRating);
                    entity.SaveChanges();
                    return;
                }
                else
                {
                    entity.UserImageRating.Remove(userImageRating);
                }
            }

            var newRate = new UserImageRating
            {
                UserId = user.Id,
                ImageId = image.Id,
                Rating = rating,
            };
            entity.UserImageRating.Add(newRate);

            entity.SaveChanges();
        }