Пример #1
0
        private void loadUsersBtn_Click(object sender, EventArgs e)
        {
            AllUsersRepository userRepo = new AllUsersRepository();
            List <AllUsers>    ulist    = userRepo.GetAllUsers();

            this.userGridView1.DataSource = ulist;
        }
Пример #2
0
 public AllUsersServices()
 {
     if (allUsersRepository == null)
     {
         allUsersRepository = new AllUsersRepository();
     }
 }
        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            BookTicketRepository bkRepo   = new BookTicketRepository();
            AllUsersRepository   userRepo = new AllUsersRepository();

            if (e.RowIndex >= 0)
            {
                AllUsers u = userRepo.GetUserById(passId);

                DataGridViewRow row = bookTicketGridView.Rows[e.RowIndex];
                int             x   = bkRepo.TicketCount();
                int             y;

                y = x + 2;

                Console.WriteLine(passId + " " + u.UserId + " " + u.UserName + " " + u.UserFullName + " - " + x);


                this.bookTicketTabs.SelectTab(1);
                flightIdLabel.Text          = row.Cells["FlightId"].Value.ToString();
                airplaneLabel.Text          = row.Cells["AirlineName"].Value.ToString();
                ticketIdLabel.Text          = y.ToString();
                passengerIdLabel.Text       = passId.ToString();
                passengerFullNameLabel.Text = u.UserFullName;
                usernameLabel.Text          = u.UserName;
                sourceLabel.Text            = row.Cells["Source"].Value.ToString();
                destinationLabel.Text       = row.Cells["Destination"].Value.ToString();
                departureLabel.Text         = row.Cells["Departure"].Value.ToString();
                costLabel.Text = row.Cells["Cost"].Value.ToString();
            }
        }
Пример #4
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            string uname = this.userTextBox1.Text;
            string upass = this.passTextBox2.Text;
            //Console.WriteLine("user: "******"pass: "******"SELECT * from AllUsers WHERE Username = '******' and Password = '******'";
            DataTable tbl         = dt.dbConnect(query);
            string    designation = "";

            try
            {
                userId      = Convert.ToInt32(tbl.Rows[0]["UserId"]);
                designation = tbl.Rows[0]["UserType"].ToString();
            }catch (Exception er)
            {
                MessageBox.Show("Wrong Password or Username");
            }
            //Console.WriteLine(designation);

            if (tbl.Rows.Count == 1)
            {
                if (designation.Equals("Admin"))
                {
                    AdminHomeForm aform = new AdminHomeForm(userId);
                    aform.Show();
                    this.Hide();
                }
                else if (designation.Equals("Employee"))
                {
                    EmployeeForm aform = new EmployeeForm(userId);
                    aform.Show();
                    this.Hide();
                }
                else if (designation.Equals("Passenger"))
                {
                    PassengerForm aform = new PassengerForm(userId);
                    aform.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Unknown User");
                }
            }
            else
            {
                passWLabel.Text = "Wrong User or Password.";
                userTextBox1.Clear();
                passTextBox2.Clear();
            }
        }
Пример #5
0
        private void submitBtn_Click(object sender, EventArgs e)
        {
            AllUsers           a     = new AllUsers();
            AllUsersRepository aRepo = new AllUsersRepository();

            a.UserFullName = this.textBox1.Text;
            a.UserName     = textBox2.Text;
            a.UserType     = "Passenger";
            a.UserQuestion = textBox10.Text;
            if (this.textBox5.Text == this.textBox4.Text)
            {
                a.UserPassword = this.textBox5.Text;


                PassengerRepository pRepo = new PassengerRepository();
                Passenger           p     = new Passenger();

                int x = pRepo.PassengerCount();
                x++;

                p.PassengerId = x;
                p.Pname       = this.textBox1.Text;
                p.Pusername   = this.textBox2.Text;
                p.Pemail      = this.textBox3.Text;
                p.Ppassword   = this.textBox5.Text;
                p.Pgender     = this.textBox6.Text;
                p.Page        = Convert.ToInt32(this.textBox7.Text);
                p.Paddress    = this.textBox9.Text;
                p.Pquestion   = this.textBox10.Text;

                if (pRepo.Insert(p) && aRepo.Insert(a))
                {
                    MessageBox.Show("New User Added");
                }
                else
                {
                    MessageBox.Show("New User not Added. \nCould not connect to database", "Insert Error");
                }

                this.textBox1.Text  = "";
                this.textBox2.Text  = "";
                this.textBox3.Text  = "";
                this.textBox4.Text  = "";
                this.textBox5.Text  = "";
                this.textBox6.Text  = "";
                this.textBox7.Text  = "";
                this.textBox9.Text  = "";
                this.textBox10.Text = "";
                //this.textBox11.Text = "";
            }
            else
            {
                wrongPasslabel.Text = "Password Don't match";
                this.textBox4.Text  = "";
                this.textBox5.Text  = "";
            }
        }
Пример #6
0
        private void searchAllBtn_Click(object sender, EventArgs e)
        {
            string             uid      = this.searchAlltextBox1.Text;
            AllUsersRepository userRepo = new AllUsersRepository();
            List <AllUsers>    aList    = new List <AllUsers>();
            AllUsers           a        = userRepo.GetUser(uid);

            aList.Add(a);


            userGridView1.DataSource = aList;
        }
Пример #7
0
        private void addEmpBtn_Click(object sender, EventArgs e)
        {
            //add emp btn
            AllUsersRepository userRepo = new AllUsersRepository();
            AllUsers           user     = new AllUsers();

            user.UserFullName = textBox71.Text;
            user.UserType     = "Employee";
            user.UserName     = textBox72.Text;
            user.UserPassword = textBox74.Text;
            user.UserQuestion = textBox79.Text;



            EmployeeRepository empRepo = new EmployeeRepository();
            Employee           emp     = new Employee();

            int x = empRepo.EmployeeCount();

            x = x + 1;

            Console.WriteLine("emp count : " + x);

            emp.EmployeeID = x;
            emp.Name       = textBox71.Text;
            emp.Username   = textBox72.Text;
            emp.Email      = textBox73.Text;
            emp.Password   = textBox74.Text;
            emp.Gender     = textBox75.Text;
            emp.Age        = Convert.ToInt32(textBox76.Text);
            emp.Address    = textBox78.Text;
            emp.Question   = textBox79.Text;

            if (empRepo.Insert(emp) && userRepo.Insert(user))
            {
                MessageBox.Show("New User Added");
                textBox71.Text = "";
                textBox72.Text = "";
                textBox73.Text = "";
                textBox74.Text = "";
                textBox75.Text = "";
                textBox76.Text = "";
                textBox78.Text = "";
                textBox79.Text = "";
            }
            else
            {
                MessageBox.Show("User not Added. Error adding employee to database.");
            }
        }
Пример #8
0
        private void button12_Click(object sender, EventArgs e)
        {
            //add admin btn
            AllUsersRepository userRepo = new AllUsersRepository();
            AllUsers           user     = new AllUsers();

            user.UserFullName = textBox81.Text;
            user.UserType     = "Admin";
            user.UserName     = textBox82.Text;
            user.UserPassword = textBox84.Text;
            user.UserQuestion = textBox89.Text;

            AdminRepository adminRepo = new AdminRepository();
            Admin           a         = new Admin();

            int x = adminRepo.AdminCount();

            x = x + 1;

            a.AdminId  = x;
            a.Name     = textBox81.Text;
            a.Username = textBox82.Text;
            a.Email    = textBox83.Text;
            a.Password = textBox84.Text;
            a.Gender   = textBox85.Text;
            a.Age      = Convert.ToInt32(textBox86.Text);
            a.Address  = textBox88.Text;
            a.Question = textBox89.Text;


            if (adminRepo.Insert(a) && userRepo.Insert(user))
            {
                MessageBox.Show("New User Added");
                textBox81.Text = "";
                textBox82.Text = "";
                textBox83.Text = "";
                textBox84.Text = "";
                textBox85.Text = "";
                textBox86.Text = "";
                textBox88.Text = "";
                textBox89.Text = "";
            }
            else
            {
                MessageBox.Show("New User did not Added. Error adding admin to database.");
            }
        }
Пример #9
0
        private void button12_Click(object sender, EventArgs e)
        {
            //add admin btn
            AdminRepository adminRepo = new AdminRepository();
            Admin           a         = new Admin();


            a.AdminId  = textBox70.Text;
            a.Name     = textBox71.Text;
            a.Username = textBox72.Text;
            a.Email    = textBox73.Text;
            a.Password = textBox74.Text;
            a.Gender   = textBox75.Text;
            a.Age      = Convert.ToInt32(textBox76.Text);
            a.Address  = textBox78.Text;
            a.Question = textBox79.Text;

            if (adminRepo.Insert(a))
            {
                AllUsersRepository userRepo = new AllUsersRepository();
                AllUsers           user     = new AllUsers();

                user.UserId   = a.AdminId;
                user.UserType = "Admin";
                user.UserName = a.Username;

                if (userRepo.Insert(user))
                {
                    MessageBox.Show("New User Added");
                }
                else
                {
                    MessageBox.Show("New User did not Added");
                }
            }
            else
            {
                MessageBox.Show("Error adding admin to database.");
            }
        }
Пример #10
0
        private void addEmpBtn_Click(object sender, EventArgs e)
        {
            EmployeeRepository empRepo = new EmployeeRepository();
            Employee           emp     = new Employee();


            emp.EmployeeID = textBox70.Text;
            emp.Name       = textBox71.Text;
            emp.Username   = textBox72.Text;
            emp.Email      = textBox73.Text;
            emp.Password   = textBox74.Text;
            emp.Gender     = textBox75.Text;
            emp.Age        = Convert.ToInt32(textBox76.Text);
            emp.Address    = textBox78.Text;
            emp.Question   = textBox79.Text;

            if (empRepo.Insert(emp))
            {
                AllUsersRepository userRepo = new AllUsersRepository();
                AllUsers           user     = new AllUsers();

                user.UserId   = emp.EmployeeID;
                user.UserType = "Employee";
                user.UserName = emp.Username;

                if (userRepo.Insert(user))
                {
                    MessageBox.Show("New User Added");
                }
                else
                {
                    MessageBox.Show("New User did not Added");
                }
            }
            else
            {
                MessageBox.Show("Error adding employee to database.");
            }
        }
Пример #11
0
        public ActionResult RemoveNotifications(string id)
        {
            User user;

            using (AllUsersRepository usersRep = new AllUsersRepository())
            {
                user = usersRep.GetList().SingleOrDefault(x => x.NotificationCode == id);
                if (user == null)
                {
                    return(Error(Loc.Dic.error_user_not_found));
                }

                user.NotificationEmail = null;
                if (usersRep.Update(user) == null)
                {
                    return(Error(Loc.Dic.error_database_error));
                }
            }

            ViewBag.Title   = Loc.Dic.RemoveNotifications;
            ViewBag.Message = Loc.Dic.NotificationsWereRemoved;
            ViewBag.Align   = "right";
            return(View());
        }
Пример #12
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (
                HttpContext.Current.Session["User"] == null
                )
            {
                var authenticatedCookie = httpContext.Request.Cookies[OpenIdMembershipService.LOGIN_COOKIE_NAME];
                if (authenticatedCookie != null)
                {
                    var authenticatedCookieValue = authenticatedCookie.Value.ToString();
                    if (!string.IsNullOrWhiteSpace(authenticatedCookieValue))
                    {
                        var user = OpenIdUser.FromCookieString(authenticatedCookieValue);

                        if (user != null && user.IsActive)
                        {
                            HttpContext.Current.Session.Add("User", user);
                        }
                        else
                        {
                            HttpCookie myCookie = new HttpCookie(OpenIdMembershipService.LOGIN_COOKIE_NAME);
                            myCookie.Expires = DateTime.Now.AddDays(-1d);
                            httpContext.Response.Cookies.Add(myCookie);
                        }
                    }
                }
            }
            else
            {
                OpenIdUser sessionUser = (OpenIdUser)HttpContext.Current.Session["User"];
                User       databaseUser;
                using (AllUsersRepository allUserRep = new AllUsersRepository())
                {
                    databaseUser = allUserRep.GetEntity(sessionUser.UserId);
                }

                if (databaseUser != null)
                {
                    sessionUser.Roles = databaseUser.Roles;
                }

                if (databaseUser == null || !databaseUser.IsActive)
                {
                    HttpContext.Current.Session.Remove("User");

                    HttpCookie myCookie = new HttpCookie(OpenIdMembershipService.LOGIN_COOKIE_NAME);
                    myCookie.Expires = DateTime.Now.AddDays(-1d);
                    HttpContext.Current.Response.Cookies.Add(myCookie);
                }
            }
            if (HttpContext.Current.Session["User"] != null)
            {
                //Create culture info object

                CultureInfo ci = new CultureInfo(((OpenIdUser)HttpContext.Current.Session["User"]).LanguageCode);
                System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                System.Threading.Thread.CurrentThread.CurrentCulture   =
                    CultureInfo.CreateSpecificCulture(ci.Name);
            }
            return(HttpContext.Current.Session["User"] != null);
        }
Пример #13
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (
                HttpContext.Current.Session["User"] == null
                )
            {
                var authenticatedCookie = httpContext.Request.Cookies[OpenIdMembershipService.LOGIN_COOKIE_NAME];
                if (authenticatedCookie != null)
                {
                    var authenticatedCookieValue = authenticatedCookie.Value.ToString();
                    if (!string.IsNullOrWhiteSpace(authenticatedCookieValue))
                    {
                        var user = OpenIdUser.FromCookieString(authenticatedCookieValue);

                        if (user != null && user.IsActive)
                        {
                            HttpContext.Current.Session.Add("User", user);
                        }
                        else
                        {
                            HttpCookie myCookie = new HttpCookie(OpenIdMembershipService.LOGIN_COOKIE_NAME);
                            myCookie.Expires = DateTime.Now.AddDays(-1d);
                            httpContext.Response.Cookies.Add(myCookie);
                        }
                    }
                }

            }
            else
            {
                OpenIdUser sessionUser = (OpenIdUser)HttpContext.Current.Session["User"];
                User databaseUser;
                using (AllUsersRepository allUserRep = new AllUsersRepository())
                {
                    databaseUser = allUserRep.GetEntity(sessionUser.UserId);
                }

                if (databaseUser != null)
                {
                    sessionUser.Roles = databaseUser.Roles;
                }

                if (databaseUser == null || !databaseUser.IsActive)
                {
                    HttpContext.Current.Session.Remove("User");

                    HttpCookie myCookie = new HttpCookie(OpenIdMembershipService.LOGIN_COOKIE_NAME);
                    myCookie.Expires = DateTime.Now.AddDays(-1d);
                    HttpContext.Current.Response.Cookies.Add(myCookie);
                }
            }
            if (HttpContext.Current.Session["User"] != null)
            {

                    //Create culture info object

                    CultureInfo ci = new CultureInfo(((OpenIdUser)HttpContext.Current.Session["User"]).LanguageCode);
                    System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                    System.Threading.Thread.CurrentThread.CurrentCulture =
                    CultureInfo.CreateSpecificCulture(ci.Name);

            }
            return HttpContext.Current.Session["User"] != null;
        }
Пример #14
0
        private LogInResult ResponseIntoUser(IAuthenticationResponse response)
        {
            LogInResult logInResult = new LogInResult();
            logInResult.IsAuthenticated = true;

            var fetchResponse = response.GetExtension<FetchResponse>();
            if (fetchResponse != null)
            {
                logInResult.User = new OpenIdUser(fetchResponse, response.ClaimedIdentifier);

                using (AllUsersRepository userRep = new AllUsersRepository())
                using (PendingUsersRepository pendingUserRep = new PendingUsersRepository())
                {
                    User user = userRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);
                    if (user != null)
                    {
                        if (user.IsActive)
                        {
                            if (user.FirstName != logInResult.User.FirstName || user.LastName != logInResult.User.LastName)
                            {
                                user.FirstName = logInResult.User.FirstName;
                                user.LastName = logInResult.User.LastName;
                                userRep.Update(user);
                            }

                            logInResult.IsRegistered = true;
                            logInResult.User.UserId = user.Id;
                            return logInResult;
                        }
                        else
                        {
                            logInResult.IsRegistered = false;
                            logInResult.IsCanceled = true;
                            logInResult.User.UserId = user.Id;
                            return logInResult;
                        }
                    }
                    else
                    {
                        PendingUser pendingUser = pendingUserRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);

                        if (pendingUser != null)
                        {
                            User newUser = new User()
                            {
                                CompanyId = pendingUser.CompanyId,
                                Email = logInResult.User.Email,
                                FirstName = logInResult.User.FirstName,
                                LastName = logInResult.User.LastName,
                                CreationTime = DateTime.Now,
                                LastLogInTime = DateTime.Now,
                                Roles = pendingUser.Roles,
                                LanguageId = pendingUser.LanguageId,
                                IsActive = true
                            };

                            if (!userRep.Create(newUser))
                                return logInResult;

                            logInResult.User.UserId = newUser.Id;
                            pendingUserRep.Delete(pendingUser.Id);

                            logInResult.IsNewUser = true;
                            logInResult.IsRegistered = true;
                            return logInResult;
                        }
                        else
                        {
                            return logInResult;
                        }
                    }
                }
            }
            else
            {
                return logInResult;
            }
        }
Пример #15
0
        public ActionResult RemoveNotifications(string id)
        {
            User user;
            using (AllUsersRepository usersRep = new AllUsersRepository())
            {
                user = usersRep.GetList().SingleOrDefault(x => x.NotificationCode == id);
                if (user == null) return Error(Loc.Dic.error_user_not_found);

                user.NotificationEmail = null;
                if (usersRep.Update(user) == null) return Error(Loc.Dic.error_database_error);
            }

            ViewBag.Title = Loc.Dic.RemoveNotifications;
            ViewBag.Message = Loc.Dic.NotificationsWereRemoved;
            ViewBag.Align = "right";
            return View();
        }
Пример #16
0
        private LogInResult ResponseIntoUser(IAuthenticationResponse response)
        {
            LogInResult logInResult = new LogInResult();

            logInResult.IsAuthenticated = true;

            var fetchResponse = response.GetExtension <FetchResponse>();

            if (fetchResponse != null)
            {
                logInResult.User = new OpenIdUser(fetchResponse, response.ClaimedIdentifier);

                using (AllUsersRepository userRep = new AllUsersRepository())
                    using (PendingUsersRepository pendingUserRep = new PendingUsersRepository())
                    {
                        User user = userRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);
                        if (user != null)
                        {
                            if (user.IsActive)
                            {
                                if (user.FirstName != logInResult.User.FirstName || user.LastName != logInResult.User.LastName)
                                {
                                    user.FirstName = logInResult.User.FirstName;
                                    user.LastName  = logInResult.User.LastName;
                                    userRep.Update(user);
                                }

                                logInResult.IsRegistered = true;
                                logInResult.User.UserId  = user.Id;
                                return(logInResult);
                            }
                            else
                            {
                                logInResult.IsRegistered = false;
                                logInResult.IsCanceled   = true;
                                logInResult.User.UserId  = user.Id;
                                return(logInResult);
                            }
                        }
                        else
                        {
                            PendingUser pendingUser = pendingUserRep.GetList().SingleOrDefault(x => x.Email == logInResult.User.Email);

                            if (pendingUser != null)
                            {
                                User newUser = new User()
                                {
                                    CompanyId     = pendingUser.CompanyId,
                                    Email         = logInResult.User.Email,
                                    FirstName     = logInResult.User.FirstName,
                                    LastName      = logInResult.User.LastName,
                                    CreationTime  = DateTime.Now,
                                    LastLogInTime = DateTime.Now,
                                    Roles         = pendingUser.Roles,
                                    LanguageId    = pendingUser.LanguageId,
                                    IsActive      = true
                                };


                                if (!userRep.Create(newUser))
                                {
                                    return(logInResult);
                                }

                                logInResult.User.UserId = newUser.Id;
                                pendingUserRep.Delete(pendingUser.Id);

                                logInResult.IsNewUser    = true;
                                logInResult.IsRegistered = true;
                                return(logInResult);
                            }
                            else
                            {
                                return(logInResult);
                            }
                        }
                    }
            }
            else
            {
                return(logInResult);
            }
        }
Пример #17
0
        public static OpenIdUser FromCookieString(string cookieString)
        {
            if (cookieString.Contains(","))
            {
                int    claimedId;
                string claimedIdString   = String.Empty;
                string claimedHashValue  = String.Empty;
                string claimedIdentifier = String.Empty;

                var stringParts = cookieString.Split(',');
                if (stringParts.Length > 0)
                {
                    claimedIdString = stringParts[0];
                }
                if (stringParts.Length > 1)
                {
                    claimedHashValue = stringParts[1];
                }
                if (stringParts.Length > 2)
                {
                    claimedIdentifier = stringParts[2];
                }

                bool isValidId = int.TryParse(claimedIdString, out claimedId);

                if (isValidId && !String.IsNullOrWhiteSpace(claimedHashValue))
                {
                    using (CookiesRepository cookiesRep = new CookiesRepository())
                        using (AllUsersRepository userRep = new AllUsersRepository())
                        {
                            bool isCookieValid = cookiesRep.GetList().Any(x => x.UserId == claimedId && x.HashValue == claimedHashValue);

                            if (isCookieValid)
                            {
                                User loggingUser = userRep.GetEntity(claimedId);

                                if (loggingUser != null)
                                {
                                    return(new OpenIdUser()
                                    {
                                        UserId = loggingUser.Id,
                                        CompanyId = loggingUser.CompanyId,
                                        CompanyName = loggingUser.Company.Name,
                                        CompanyCoinSign = loggingUser.Company.CoinSign,
                                        Email = loggingUser.Email,
                                        NotificationEmail = loggingUser.NotificationEmail,
                                        NotificationCode = loggingUser.NotificationCode,
                                        FirstName = loggingUser.FirstName,
                                        LastName = loggingUser.LastName,
                                        Roles = loggingUser.Roles,
                                        CreationTime = loggingUser.CreationTime,
                                        LastLogInTime = loggingUser.LastLogInTime,
                                        IsSignedByProvider = false,
                                        ClaimedIdentifier = claimedIdentifier,
                                        OrdersApprovalRouteId = loggingUser.DefaultApprovalRouteId,
                                        IsActive = loggingUser.IsActive,
                                        LanguageCode = loggingUser.Language.Code
                                    });
                                }
                            }
                        }
                }
            }

            return(null);
        }