public static void ActivateUser(string email) { var entity = new ImageNetworkEntities(); entity.User.FirstOrDefault(a => a.Email == email).IsBlock = false; entity.SaveChanges(); }
public static void AddFilter(int imageId, int filterId) { var entity = new ImageNetworkEntities(); entity.Image.FirstOrDefault(a => a.Id == imageId).Filter.Add(entity.Filter.FirstOrDefault(a => a.Id == filterId)); entity.SaveChanges(); }
public static void AddUser(User user) { var entity = new ImageNetworkEntities(); entity.User.Add(user); entity.SaveChanges(); }
public static void AddImage(Image image, string tags, bool[] filters) { var entity = new ImageNetworkEntities(); if (tags != null) { string[] tagList = tags.Split(new Char[] { ' ', ',' }); foreach (var item in tagList) { if (item == "") continue; var tag = new Tag { Name = item, }; tag.Name = tag.Name.TrimEnd().ToLower(); if (entity.Tag.FirstOrDefault(a => a.Name == tag.Name) != null) { tag = entity.Tag.FirstOrDefault(a => a.Name == tag.Name); } image.Tag.Add(tag); entity.SaveChanges(); } for (int filterId = 1; filterId < filters.Length+1; filterId++) { if (filters[filterId - 1]) image.Filter.Add(entity.Filter.FirstOrDefault(a => a.Id == filterId)); } } entity.Image.Add(image); entity.SaveChanges(); }
public static void AddTag(Tag tag) { var entity = new ImageNetworkEntities(); tag.Name = tag.Name.TrimEnd().ToLower(); if (entity.Tag.FirstOrDefault(a => a.Name == tag.Name) == null) { entity.Tag.Add(tag); entity.SaveChanges(); } }
public static void DeleteImage(int id) { var entity = new ImageNetworkEntities(); Image image = entity.Image.FirstOrDefault(a => a.Id == id); MvcApplication1.Helpers.ImageHelper.DeleteFile(image.Picture); MvcApplication1.Helpers.ImageHelper.DeleteFile(image.SmallPicture); image.Tag.Clear(); UserImageRating[] ratings = entity.UserImageRating.Where(a => a.ImageId == id).ToArray(); foreach (var item in ratings) { entity.UserImageRating.Remove(item); } entity.Image.Remove(image); entity.SaveChanges(); }
public static User GetUser(string email, string password) { var entity = new ImageNetworkEntities(); return entity.User.FirstOrDefault(u => u.Email == email && u.Password == password); }
public static User GetUser(int id) { var entity = new ImageNetworkEntities(); return entity.User.FirstOrDefault(u => u.Id == id); }
public static User GetUser(string cookies) { var entity = new ImageNetworkEntities(); return entity.User.FirstOrDefault(u => u.Cookies == cookies); }
public static List<string> GetTagsByImageId(int imageId) { var entity = new ImageNetworkEntities(); var image = entity.Image.FirstOrDefault(a => a.Id == imageId); List<string> res = new List<string>(); foreach (var item in image.Tag.ToArray()) { res.Add(item.Name); } return res; }
public static int GetTotalRating(int imageId) { var entity = new ImageNetworkEntities(); int result = 0; Image image = entity.Image.FirstOrDefault(a => a.Id == imageId); UserImageRating[] ratings = image.UserImageRating.Where(a => a.ImageId == imageId).ToArray(); foreach (var item in ratings) { result += (int)item.Rating; } return result; }
public static Image GetImage(int id) { var entity = new ImageNetworkEntities(); return entity.Image.FirstOrDefault(u => u.Id == id); }
public static User[] GetAllUsers() { var entity = new ImageNetworkEntities(); return entity.User.ToArray(); }
public static Tag GetTag(string name) { var entity = new ImageNetworkEntities(); return entity.Tag.FirstOrDefault(a => a.Name == name); }
public static string MakeWebkitValue(int imageId) { var entity = new ImageNetworkEntities(); var image = entity.Image.FirstOrDefault(a => a.Id == imageId); string result = ""; if (image.Filter.FirstOrDefault(a => a.Id == 1) != null) { if (image.Filter.FirstOrDefault(a => a.Id == 1) != null) { result += "sepia(100%)"; } if (image.Filter.FirstOrDefault(a => a.Id == 2) != null) { result += "grayscale(100%)"; } if (image.Filter.FirstOrDefault(a => a.Id == 3) != null) { result += "contrast(200%)"; } } return result; }
public static Image[] GetSortedImages() { var entity = new ImageNetworkEntities(); var sortedImages = from n in entity.Image.ToArray() orderby (-1)*GetTotalRating(n.Id) select n; return sortedImages.ToArray(); }
public static int GetRating(int imageId, int userId) { var entity = new ImageNetworkEntities(); Image image = entity.Image.FirstOrDefault(a => a.Id == imageId); UserImageRating userImageRating = image.UserImageRating.FirstOrDefault(a => a.ImageId == imageId && a.UserId == userId); if (userImageRating == null) { return 0; } else { return (int)userImageRating.Rating; } }
public static Image[] GetLatestImages() { var entity = new ImageNetworkEntities(); var sortedImages = from n in entity.Image.ToArray() orderby n.PostDate descending select n; return sortedImages.ToArray(); }
public static Image[] GetImagesByUserId(int userId) { var entity = new ImageNetworkEntities(); var user = entity.User.FirstOrDefault(u => u.Id == userId); return user.Image.ToArray(); }
public static Image[] GetImagesByTag(string tagName) { var entity = new ImageNetworkEntities(); return entity.Image.Where(a => a.Tag.FirstOrDefault(t => t.Name == tagName) != null).ToArray(); }
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(); }
public static Filter GetFilter(int id) { var entity = new ImageNetworkEntities(); return entity.Filter.FirstOrDefault(a => a.Id == id); }
public static Tag GetTag(int id) { var entity = new ImageNetworkEntities(); return entity.Tag.FirstOrDefault(a => a.Id == id); }
public static int GetTagEnterance(string tagName) { var entity = new ImageNetworkEntities(); return entity.Tag.FirstOrDefault(a => a.Name == tagName).Image.ToArray().Length; }
public static Image[] GetAllImages() { var entity = new ImageNetworkEntities(); return entity.Image.ToArray(); }
public static Tag[] GetAllTags() { var entity = new ImageNetworkEntities(); return entity.Tag.ToArray(); }