예제 #1
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            var searchTerm = SearchTerm.Text.ToLower();

            var placesToReturn = new List <Place>();

            using (var db = new PointsOfInterestContext())
            {
                placesToReturn = db.Places
                                 .Where(x => (x.IsDeleted == false || x.IsDeleted == null) &&
                                        x.PlaceName.ToLower().Contains(searchTerm))
                                 .ToList();

                foreach (var item in placesToReturn)
                {
                    var ratesPlaces = db.Rates_Users_Places
                                      .Where(x => x.PlaceId == item.Id).ToList();

                    item.Rate = CalculateAverageRate(ratesPlaces);
                }
            }

            places.ItemsSource = placesToReturn;
            places.Items.Refresh();
        }
예제 #2
0
        private void SeedFromFile_Click(object sender, RoutedEventArgs e)
        {
            var dir         = System.IO.Directory.GetParent(Environment.CurrentDirectory).ToString();
            var path        = System.IO.Path.GetDirectoryName(dir);
            var combinePath = System.IO.Path.Combine(path + "/Files/PLaces" + ".txt");
            var lines       = System.IO.File.ReadAllLines(combinePath);

            var items = new List <Place>();

            foreach (var line in lines)
            {
                var splitLine = line.Split(';');
                var name      = splitLine[0];
                var img       = splitLine[1];
                var des       = splitLine[2];

                var item = new Place
                {
                    PlaceName   = name,
                    ImageUrl    = img,
                    Descripiton = des
                };
                items.Add(item);
            }

            using (var db = new PointsOfInterestContext())
            {
                foreach (var item in items)
                {
                    var existItem = db.Places.SingleOrDefault(x => x.PlaceName == item.PlaceName);

                    if (existItem == null)
                    {
                        db.Places.Add(item);
                    }
                }

                db.SaveChanges();
            }

            var itemsToReturn = new List <Place>();

            using (var db = new PointsOfInterestContext())
            {
                itemsToReturn = db.Places
                                .Where(x => (x.IsDeleted == false || x.IsDeleted == null))
                                .ToList();

                foreach (var item in itemsToReturn)
                {
                    var ratesPlaces = db.Rates_Users_Places
                                      .Where(x => x.PlaceId == item.Id).ToList();

                    item.Rate = this.CalculateAverageRate(ratesPlaces);
                }
            }

            places.ItemsSource = itemsToReturn;
            places.Items.Refresh();
        }
예제 #3
0
        private void ViewComments_Button(object sender, RoutedEventArgs e)
        {
            var comments = new List <Comment>();

            using (var db = new PointsOfInterestContext())
            {
                var museum = db.Museums.SingleOrDefault(x => x.Id == this.Mus.Id);
                comments = museum.Comments.ToList();
            }
            var commentWindow = new CommentWindow(comments);

            commentWindow.Show();
            this.Close();
        }
예제 #4
0
        private void DeleteRateBtn_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new PointsOfInterestContext())
            {
                var currentUser = db.Users.SingleOrDefault(x => x.Email == this.UserEmail);
                var currentRate = db.Rates_Users_Museums
                                  .SingleOrDefault(x => x.UserId == currentUser.Id && x.MuseumId == this.Mus.Id);

                db.Rates_Users_Museums.Remove(currentRate);
                db.SaveChanges();
            }

            var page = new MuseumWindow(this.Mus.Id.ToString());

            page.Show();
            this.Close();
        }
예제 #5
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            try
            {
                var selectedItem = places.SelectedItem as Place;
                using (var db = new PointsOfInterestContext())
                {
                    var deletedItem = db.Places.SingleOrDefault(x => x.Id == selectedItem.Id);
                    deletedItem.IsDeleted = true;

                    db.SaveChanges();
                }
            }
            catch
            {
            }
        }
예제 #6
0
        private void AddRate_Button(object sender, RoutedEventArgs e)
        {
            var parsedRateNumber = 0;

            var parsedRate = Int32.TryParse(MusRate.Value.ToString(), out parsedRateNumber);

            if (parsedRate)
            {
                if (parsedRateNumber < 1 || parsedRateNumber > 5)
                {
                    MessageBox.Show("rate must be between 1 and 5");
                }
                else
                {
                    using (var db = new PointsOfInterestContext())
                    {
                        var currentUser = db.Users.SingleOrDefault(x => x.Email == this.UserEmail);

                        if (!this.IsRated)
                        {
                            var rateMuseum = new Rates_Users_Museums
                            {
                                UserId   = currentUser.Id,
                                MuseumId = this.Mus.Id,
                                Rate     = parsedRateNumber
                            };

                            db.Rates_Users_Museums.Add(rateMuseum);
                            db.SaveChanges();
                        }
                    }

                    var page = new MuseumWindow(this.Mus.Id.ToString());
                    page.Show();
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("rate must be a number");
            }
        }
예제 #7
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var email    = txtemail.Text.Trim();
            var password = txtpassword.Password.Trim();

            using (var db = new PointsOfInterestContext())
            {
                var existUser = db.Users.SingleOrDefault(x => x.Email == email);

                if (existUser == null)
                {
                    MessageBox.Show("Invalid email or password");
                }
                else
                {
                    var checkPassword = BCrypt.Net.BCrypt.Verify(password, existUser.Password);
                    if (checkPassword)
                    {
                        UserLogger.Save(email, existUser.Name);

                        ConfigurationManager.AppSettings["CurrentUser"] = existUser.Email;

                        var isAdmin      = existUser.IsAdmin ?? false;
                        var adminMessage = "";
                        if (isAdmin)
                        {
                            adminMessage = "with admin permissions";
                        }
                        MessageBox.Show($"You have succesfully logged in with {existUser.Email} {adminMessage}");

                        var page = new Home();
                        page.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Invalid email or password");
                    }
                }
            }
        }
        private List <Hotel> LoadCollectionData()
        {
            var hotelsToReturn = new List <Hotel>();

            using (var db = new PointsOfInterestContext())
            {
                hotelsToReturn = db.Hotels
                                 .Where(x => x.IsDeleted == false || x.IsDeleted == null)
                                 .ToList();

                foreach (var item in hotelsToReturn)
                {
                    var ratesHotel = db.Rates_Users_Hotels
                                     .Where(x => x.HotelId == item.Id).ToList();

                    item.Rate = this.CalculateAverageRate(ratesHotel);
                }
            }

            return(hotelsToReturn);
        }
예제 #9
0
        private void AddComment_Button(object sender, RoutedEventArgs e)
        {
            var commentText = CommentVal.Text;

            if (!string.IsNullOrEmpty(commentText))
            {
                using (var db = new PointsOfInterestContext())
                {
                    var comment = new Comment();
                    comment.Name      = commentText;
                    comment.UserEmail = this.UserEmail;

                    var museum = db.Museums.SingleOrDefault(x => x.Id == this.Mus.Id);
                    museum.Comments.Add(comment);

                    db.SaveChanges();
                }
            }

            CommentVal.Text = "";
        }
예제 #10
0
        private List <Place> LoadCollectionData()
        {
            var placesToReturn = new List <Place>();

            using (var db = new PointsOfInterestContext())
            {
                placesToReturn = db.Places
                                 .Where(x => x.IsDeleted == false || x.IsDeleted == null)
                                 .ToList();

                foreach (var item in placesToReturn)
                {
                    var ratesPlaces = db.Rates_Users_Places
                                      .Where(x => x.PlaceId == item.Id).ToList();

                    item.Rate = CalculateAverageRate(ratesPlaces);
                }
            }

            return(placesToReturn);
        }
예제 #11
0
        private List <Museum> LoadCollectionData()
        {
            var museumsToReturn = new List <Museum>();

            using (var db = new PointsOfInterestContext())
            {
                museumsToReturn = db.Museums
                                  .Where(x => x.IsDeleted == false || x.IsDeleted == null)
                                  .ToList();

                foreach (var item in museumsToReturn)
                {
                    var ratesMuseum = db.Rates_Users_Museums
                                      .Where(x => x.MuseumId == item.Id).ToList();

                    item.AverageRate = CalculateAverageRate(ratesMuseum);
                }
            }

            return(museumsToReturn);
        }
예제 #12
0
        private void LockButtons()
        {
            using (var db = new PointsOfInterestContext())
            {
                var currentUser = db.Users.SingleOrDefault(x => x.Email == this.UserEmail);
                this.IsRated = db.Rates_Users_Museums
                               .Any(x => x.MuseumId == this.Mus.Id && x.UserId == currentUser.Id);

                if (this.IsRated)
                {
                    MusRate.Visibility       = Visibility.Hidden;
                    RateBtn.Visibility       = Visibility.Hidden;
                    DeleteRateBtn.Visibility = Visibility.Visible;
                }
                else
                {
                    MusRate.Visibility       = Visibility.Visible;
                    RateBtn.Visibility       = Visibility.Visible;
                    DeleteRateBtn.Visibility = Visibility.Hidden;
                }
            }
        }
        private bool IsAdmin()
        {
            try
            {
                string currentUserEmail = ConfigurationManager.AppSettings["CurrentUser"];

                using (var db = new PointsOfInterestContext())
                {
                    var currentUser = db.Users.SingleOrDefault(x => x.Email == currentUserEmail);
                    var isAdmin     = currentUser.IsAdmin ?? false;

                    if (isAdmin)
                    {
                        return(true);
                    }
                }
            }
            catch
            {
            }

            return(false);
        }
예제 #14
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var musName   = MusName.Text;
            var musDes    = MusDes.Text;
            var imagePath = MusImageName.Text;

            if (!String.IsNullOrEmpty(musName) && !String.IsNullOrEmpty(musDes) &&
                !String.IsNullOrEmpty(imagePath))
            {
                var imageName = ImageSaver.Save("Museums", imagePath);

                var museum = new Museum();
                museum.MuseumName  = musName;
                museum.Descripiton = musDes;
                museum.ImageUrl    = imageName;

                using (var db = new PointsOfInterestContext())
                {
                    db.Museums.Add(museum);

                    db.SaveChanges();
                }

                MusName.Text      = "";
                MusDes.Text       = "";
                MusImageName.Text = "";

                museums.ItemsSource = this.LoadCollectionData();
                museums.Items.Refresh();

                ErrrorMessage.Content = "";
            }
            else
            {
                ErrrorMessage.Content = "Name, Description, Image Name cannot be empty";
            }
        }
예제 #15
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var placeName = PlaceName.Text;
            var placeDes  = PlaceDes.Text;
            var imagePath = PlaceImageName.Text;

            if (!String.IsNullOrEmpty(placeName) && !String.IsNullOrEmpty(placeDes) &&
                !String.IsNullOrEmpty(imagePath))
            {
                var imageName = ImageSaver.Save("Places", imagePath);
                var place     = new Place();
                place.PlaceName   = placeName;
                place.Descripiton = placeDes;
                place.ImageUrl    = imageName;

                using (var db = new PointsOfInterestContext())
                {
                    db.Places.Add(place);

                    db.SaveChanges();
                }

                PlaceName.Text      = "";
                PlaceDes.Text       = "";
                PlaceImageName.Text = "";

                places.ItemsSource = this.LoadCollectionData();
                places.Items.Refresh();

                ErrrorMessage.Content = "";
            }
            else
            {
                ErrrorMessage.Content = "Name, Description, Image Name cannot be empty";
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var name      = HotelName.Text;
            var des       = HotelDes.Text;
            var imagePath = HotelImageName.Text;
            var place     = HotelPlace.Text;
            var price     = HotelPrice.Text;

            var parsedPriceNumber = 0.00m;

            if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(des) &&
                !String.IsNullOrEmpty(imagePath) && !String.IsNullOrEmpty(place) &&
                !String.IsNullOrEmpty(price))
            {
                var parsedPrice = Decimal.TryParse(price, out parsedPriceNumber);

                if (parsedPrice)
                {
                    if (parsedPriceNumber < 0)
                    {
                        ErrrorMessage.Content = "Price cannot be a negative number";
                    }
                    else
                    {
                        var imageName = ImageSaver.Save("Hotels", imagePath);
                        var hotel     = new Hotel();
                        hotel.HotelName   = name;
                        hotel.Descripiton = des;
                        hotel.ImageUrl    = imageName;
                        hotel.Place       = place;
                        hotel.Price       = parsedPriceNumber;

                        using (var db = new PointsOfInterestContext())
                        {
                            db.Hotels.Add(hotel);

                            db.SaveChanges();
                        }

                        HotelName.Text      = "";
                        HotelDes.Text       = "";
                        HotelImageName.Text = "";
                        HotelPlace.Text     = "";
                        HotelPrice.Text     = "";

                        hotels.ItemsSource = this.LoadCollectionData();
                        hotels.Items.Refresh();

                        ErrrorMessage.Content = "";
                    }
                }
                else
                {
                    ErrrorMessage.Content = "Price must be a number";
                }
            }
            else
            {
                ErrrorMessage.Content = "Name, Description, Image Name, Place and Price cannot be empty";
            }
        }
예제 #17
0
        private void LoadData(string id)
        {
            try
            {
                var idToNumber = int.Parse(id);
                using (var db = new PointsOfInterestContext())
                {
                    var museum      = db.Museums.SingleOrDefault(x => x.Id == idToNumber);
                    var currentUser = db.Users.SingleOrDefault(x => x.Email == this.UserEmail);

                    if (museum == null)
                    {
                        throw new ArgumentNullException("Invalid museum Id");
                    }
                    else
                    {
                        this.Mus = museum;

                        var ratesMus = db.Rates_Users_Museums
                                       .Where(x => x.MuseumId == this.Mus.Id).ToList();

                        var averageRate = 0.0m;
                        if (ratesMus.Count > 0)
                        {
                            var fiveCount  = ratesMus.Count(x => x.Rate == 5);
                            var fourCount  = ratesMus.Count(x => x.Rate == 4);
                            var threeCount = ratesMus.Count(x => x.Rate == 3);
                            var twoCount   = ratesMus.Count(x => x.Rate == 2);
                            var oneCount   = ratesMus.Count(x => x.Rate == 1);

                            averageRate = RateCalculator.Calculcate(fiveCount, fourCount, threeCount, twoCount, oneCount);
                        }

                        museum.AverageRate = averageRate;


                        var currentUserRate = db.Rates_Users_Museums
                                              .SingleOrDefault(x => x.MuseumId == this.Mus.Id && x.UserId == currentUser.Id);
                        if (currentUserRate != null)
                        {
                            YourRateLabel.Content = "Your rate is : " + currentUserRate.Rate;
                        }

                        AverageRate.Value = (int)Math.Round(averageRate);


                        MusDes.Content  = museum.Descripiton;
                        MusName.Content = museum.MuseumName;

                        var dir       = System.IO.Directory.GetParent(Environment.CurrentDirectory).ToString();
                        var path      = System.IO.Path.GetDirectoryName(dir);
                        var imagePath = System.IO.Path.Combine(path + "/Images/Museums/" + museum.ImageUrl);
                        //Uri resourceUri = new Uri(imagePath, UriKind.Relative);
                        BitmapImage bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.UriSource = new Uri(imagePath);
                        bitmap.EndInit();
                        MusImg.Source = bitmap;
                    }
                }
            }
            catch
            {
            }
        }
예제 #18
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var email    = txtemail.Text.Trim();
            var name     = txtname.Text.Trim();
            var password = txtpassword.Password.Trim();

            var errorMessage = "";

            if (email == "" || name == "" || password == "")
            {
                errorMessage = "Please fill all details";
                MessageBox.Show(errorMessage);
                return;
            }

            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match = regex.Match(email);

            if (!match.Success)
            {
                errorMessage = "Invalid email address";
                MessageBox.Show(errorMessage);
                return;
            }

            if (!string.IsNullOrEmpty(name) && !Char.IsUpper(name[0]))
            {
                errorMessage = "Name must start with UpperCase";
                MessageBox.Show(errorMessage);
                return;
            }

            if (name.Length <= 3)
            {
                errorMessage = "Name must be more than 3 symbols!";
                MessageBox.Show(errorMessage);
                return;
            }

            Regex regexPass = new Regex(@"^(?=.{6,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+*!=]).*$");
            Match matchPass = regexPass.Match(password);

            if (!matchPass.Success)
            {
                errorMessage = "Password must have atleast 6 symbols and contains one upper case, one lower case and one special symbol(@#$%^&+*!=)";
                MessageBox.Show(errorMessage);
                return;
            }

            try
            {
                using (var db = new PointsOfInterestContext())
                {
                    var user = db.Users.SingleOrDefault(x => x.Email == email);

                    if (user == null)
                    {
                        user       = new User();
                        user.Email = email;
                        user.Name  = name;

                        string passwordHashed = BCrypt.Net.BCrypt.HashPassword(password,
                                                                               BCrypt.Net.BCrypt.GenerateSalt());
                        user.Password = passwordHashed;
                        user.IsAdmin  = false;

                        db.Users.Add(user);
                        db.SaveChanges();

                        MessageBox.Show("Registration Successfull.");
                        Login log = new Login();
                        log.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("This email is already register");
                    }
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }