Пример #1
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();
        }
Пример #2
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();
        }
Пример #3
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
            {
            }
        }
Пример #4
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");
            }
        }
Пример #5
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 = "";
        }
Пример #6
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";
            }
        }
Пример #7
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";
            }
        }
Пример #8
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;
            }
        }
        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";
            }
        }