コード例 #1
0
ファイル: ItemService.cs プロジェクト: nayots/RPGHelper
 public static Item GetItemById(Item item)
 {
     using (var context = new RPGHelperContext())
     {
         return(context.Items.FirstOrDefault(i => i.Id == item.Id));
     }
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
 public static void Refresh()
 {
     using (var context = new RPGHelperContext())
     {
         loggedUser = context.Users.FirstOrDefault(u => u.Username.Equals(loggedUser.Username) && u.Password.Equals(loggedUser.Password));
     }
 }
コード例 #4
0
 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());
     }
 }
コード例 #5
0
ファイル: ItemService.cs プロジェクト: nayots/RPGHelper
 public static ObservableCollection <Item> GetAllItems()
 {
     using (var context = new RPGHelperContext())
     {
         return(new ObservableCollection <Item>(context.Items));
     }
 }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
 public bool UserExists(string username)
 {
     using (var context = new RPGHelperContext())
     {
         return(context.Users.Any(u => u.Username == username));
     }
 }
コード例 #8
0
 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());
     }
 }
コード例 #9
0
 public IEnumerable GetFriends(int id)
 {
     using (var context = new RPGHelperContext())
     {
         return(context.Users.FirstOrDefault(u => u.Id == id).Friends.OrderBy(f => f.Username).ToList());
     }
 }
コード例 #10
0
 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());
     }
 }
コード例 #11
0
ファイル: ItemService.cs プロジェクト: nayots/RPGHelper
 public static ItemStats GetItemStatsById(int id)
 {
     using (var context = new RPGHelperContext())
     {
         return(context.ItemStatistics.FirstOrDefault(it => it.Item.Id == id));
     }
 }
コード例 #12
0
        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()));
            }
        }
コード例 #13
0
        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();
            }
        }
コード例 #14
0
ファイル: ItemService.cs プロジェクト: nayots/RPGHelper
 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();
     }
 }
コード例 #15
0
ファイル: HeroesView.xaml.cs プロジェクト: nayots/RPGHelper
        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();
        }
コード例 #16
0
ファイル: HeroesView.xaml.cs プロジェクト: nayots/RPGHelper
        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();
        }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
ファイル: ItemService.cs プロジェクト: nayots/RPGHelper
        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();
        }
コード例 #19
0
ファイル: HeroesView.xaml.cs プロジェクト: nayots/RPGHelper
        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()
                               );
        }
コード例 #20
0
        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();
            }
        }
コード例 #21
0
        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();
            }
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
ファイル: HeroesView.xaml.cs プロジェクト: nayots/RPGHelper
        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();
            }
        }
コード例 #24
0
        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();
            }
        }
コード例 #25
0
ファイル: ItemService.cs プロジェクト: nayots/RPGHelper
        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();
                }
            }
        }
コード例 #26
0
ファイル: HeroesView.xaml.cs プロジェクト: nayots/RPGHelper
        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!");
            }
        }
コード例 #27
0
        public User GetUser(int id, RPGHelperContext context)
        {
            var user = context.Users.FirstOrDefault(u => u.Id == id);

            return(user);
        }
コード例 #28
0
        public User GetUser(string username, RPGHelperContext context)
        {
            var user = context.Users.FirstOrDefault(u => u.Username == username);

            return(user);
        }