public static Item GetItemById(Item item) { using (var context = new RPGHelperContext()) { return(context.Items.FirstOrDefault(i => i.Id == item.Id)); } }
public void EditProfile(string firstName, string lastName, string email, DateTime?date, string password, string genderValue) { using (var context = new RPGHelperContext()) { int userId = AuthenticationService.GetCurrentUser().Id; var user = context.Users.FirstOrDefault(u => u.Id == userId); user.FirstName = firstName; user.LastName = lastName; user.Email = email; user.Birthdate = date; user.Password = password; Gender gen = Gender.NotSpecified; Enum.TryParse(genderValue, out gen); user.Gender = gen; context.SaveChanges(); AuthenticationService.Logout(); AuthenticationService.Login(user.Username, user.Password); } }
public static void Refresh() { using (var context = new RPGHelperContext()) { loggedUser = context.Users.FirstOrDefault(u => u.Username.Equals(loggedUser.Username) && u.Password.Equals(loggedUser.Password)); } }
public IEnumerable GetReceivedMessages(int id) { using (var context = new RPGHelperContext()) { return(context.Messages.Include("Sender").Where(m => m.RecipientId == id && m.IsDeleted == false).OrderByDescending(o => o.SentOn).ToList()); } }
public static ObservableCollection <Item> GetAllItems() { using (var context = new RPGHelperContext()) { return(new ObservableCollection <Item>(context.Items)); } }
public void ChangeProfilePicture(string imageName) { using (var context = new RPGHelperContext()) { var userId = AuthenticationService.GetCurrentUser().Id; var user = context.Users.FirstOrDefault(u => u.Id == userId); string oldImage = user.ImgPath; if (oldImage != "anonymous-person.png" && !oldImage.Contains("stock")) { try { File.Delete($@"..\..\Media\ProfilePictures\{oldImage}"); } catch (Exception) { } } user.ImgPath = imageName; context.SaveChanges(); AuthenticationService.Refresh(); } }
public bool UserExists(string username) { using (var context = new RPGHelperContext()) { return(context.Users.Any(u => u.Username == username)); } }
public IEnumerable GetFriendsUsernames(int id, string filter) { using (var context = new RPGHelperContext()) { return(context.Users.FirstOrDefault(u => u.Id == id).Friends.OrderBy(f => f.Username).Where(f => f.Username.ToLower().Contains(filter.ToLower())).Select(uf => uf.Username).ToList()); } }
public IEnumerable GetFriends(int id) { using (var context = new RPGHelperContext()) { return(context.Users.FirstOrDefault(u => u.Id == id).Friends.OrderBy(f => f.Username).ToList()); } }
public IEnumerable GetSentMessages(int id) { using (var context = new RPGHelperContext()) { return(context.Messages.Include("Recipient").Where(m => m.Sender.Id == id).OrderByDescending(o => o.SentOn).ToList()); } }
public static ItemStats GetItemStatsById(int id) { using (var context = new RPGHelperContext()) { return(context.ItemStatistics.FirstOrDefault(it => it.Item.Id == id)); } }
public bool HasFriend(string foundUsername) { using (var context = new RPGHelperContext()) { int userId = AuthenticationService.GetCurrentUser().Id; return(context.Users.FirstOrDefault(u => u.Id == userId).Friends.Any(f => f.Username.ToLower() == foundUsername.ToLower())); } }
public void MarkAsDeleted(int msgId) { using (var context = new RPGHelperContext()) { var msg = context.Messages.Include("Sender").Include("Recipient").FirstOrDefault(m => m.Id == msgId); msg.IsDeleted = true; context.SaveChanges(); } }
public static void SaveItem(Item item, ItemStats itemStat) { using (var context = new RPGHelperContext()) { itemStat.Item = item; context.ItemStatistics.Add(itemStat); context.Items.Add(item); context.SaveChanges(); } }
private void EditHero_OnClick(object sender, RoutedEventArgs e) { var context = new RPGHelperContext(); Button b = sender as Button; var currentHeroId = (int)b.DataContext; var currentHero = context.Heroes.FirstOrDefault(h => h.Id == currentHeroId); var edditHero = new EditHeroView(currentHero); edditHero.Show(); LoadData(); }
private void HeroAddItem_OnClick_Click(object sender, RoutedEventArgs e) { var context = new RPGHelperContext(); Button b = sender as Button; var currentHeroId = (int)b.DataContext; var currentHero = context.Heroes.FirstOrDefault(h => h.Id == currentHeroId); var heroAddItem = new HeroAddItemView(currentHero); heroAddItem.Show(); LoadData(); }
public Message GetMessageById(int msgId) { using (var context = new RPGHelperContext()) { var msg = context.Messages.Include("Sender").Include("Recipient").FirstOrDefault(m => m.Id == msgId); msg.IsRead = true; context.SaveChanges(); return(msg); } }
public static void SaveChanges(Item item, int id, RPGHelperContext context) { var itemToSave = context.Items.Find(id); itemToSave.Cost = item.Cost; itemToSave.Description = item.Description; itemToSave.ItemStats = item.ItemStats; itemToSave.Name = item.Name; itemToSave.Rarity = item.Rarity; itemToSave.Slot = item.Slot; itemToSave.ItemType = item.ItemType; context.SaveChanges(); }
public void LoadData() { var context = new RPGHelperContext(); var user = AuthenticationService.GetCurrentUser(); this.DataContext = new ObservableCollection <Hero> ( context.Heroes .Where(h => h.UserId == user.Id) .OrderBy(h => h.Name) .ToList() ); }
public void Register(string username, string password) { using (var context = new RPGHelperContext()) { User user = new User { Username = username, Password = password }; context.Users.Add(user); context.SaveChanges(); } }
public void RemoveFriend(string username) { using (var context = new RPGHelperContext()) { int userId = AuthenticationService.GetCurrentUser().Id; var user = context.Users.FirstOrDefault(u => u.Id == userId); var friend = context.Users.FirstOrDefault(u => u.Username.ToLower() == username.ToLower()); user.Friends.Remove(friend); context.SaveChanges(); } }
public static bool Login(string username, string password) { using (var context = new RPGHelperContext()) { loggedUser = context.Users.FirstOrDefault(u => u.Username.Equals(username) && u.Password.Equals(password)); } if (loggedUser != null) { return(true); } else { return(false); } }
private void HeroRemoveOwnedItem_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; Item currentItem = button.DataContext as Item; int itemId = currentItem.Id; var currentHeroId = (HeroesList.SelectedItem as Hero).Id; using (var context = new RPGHelperContext()) { var hero = context.Heroes.FirstOrDefault(h => h.Id == currentHeroId); var item = context.Items.FirstOrDefault(i => i.Id == itemId); if (hero != null) { hero.Items.Remove(item); context.SaveChanges(); } LoadData(); } }
public void SendMessage(string usernameSelected, string subject, string content) { using (var context = new RPGHelperContext()) { int userId = AuthenticationService.GetCurrentUser().Id; var sender = context.Users.FirstOrDefault(u => u.Id == userId); var recipient = context.Users.FirstOrDefault(u => u.Username == usernameSelected); Message msg = new Message { Subject = subject, Content = content, Sender = sender, Recipient = recipient, SentOn = DateTime.Now }; context.Messages.Add(msg); context.SaveChanges(); } }
public static void Remove(Item item) { using (var context = new RPGHelperContext()) { Item itemToRemove = context.Items.FirstOrDefault(i => i.Id == item.Id); ItemStats itemStats = context.ItemStatistics.FirstOrDefault(st => st.Item.Id == item.Id); if (itemStats != null) { context.ItemStatistics.Remove(itemStats); context.SaveChanges(); } else { Console.WriteLine("gluposti"); } if (itemToRemove != null) { context.Items.Remove(itemToRemove); context.SaveChanges(); } } }
private void DeleteHero_Click(object sender, RoutedEventArgs e) { var context = new RPGHelperContext(); Button b = sender as Button; var currentHeroId = (int)b.DataContext; var currentHero = context.Heroes.FirstOrDefault(h => h.Id == currentHeroId); var result = MessageBox.Show("Are you sure you want to delete this Hero?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes && currentHero != null) { using (context = new RPGHelperContext()) { Hero heroToRemove = context.Heroes.FirstOrDefault(h => h.Id == currentHero.Id); HeroStats heroStats = context.HeroStatistics.FirstOrDefault(hs => hs.Hero.Id == currentHero.Id); if (heroStats != null) { context.HeroStatistics.Remove(heroStats); context.SaveChanges(); } if (heroToRemove != null) { context.Heroes.Remove(heroToRemove); context.SaveChanges(); } } MessageBox.Show("Hero removed successfully!"); LoadData(); } if (currentHero == null) { MessageBox.Show("This Hero is not added yet!"); } }
public User GetUser(int id, RPGHelperContext context) { var user = context.Users.FirstOrDefault(u => u.Id == id); return(user); }
public User GetUser(string username, RPGHelperContext context) { var user = context.Users.FirstOrDefault(u => u.Username == username); return(user); }