Exemple #1
0
        public void Add_Person_FirstAdmin_And_Customers(List <string> pp)
        {
            using (var db01 = new ConnectingDB())
            {
                //first person add (as admin):
                var p = db01.person1.FirstOrDefault();
                if (p == null)
                {
                    Person per = new Person
                    {
                        FirstName = pp[0], LastName = pp[1], Birthday_Day = pp[2], Birthday_Month = pp[3], Birthday_Year = pp[4], E_Mail = pp[5], Gender = pp[8], Mobil = pp[6], PassWord = pp[10], UserName = pp[9], Picture = pp[11], Telephon = pp[7], Sath_E_Dastresy = "0"
                    };

                    db01.person1.Add(per);
                    db01.SaveChanges();
                }
                //other person add(as customer)
                else if (p != null)
                {
                    Person per = new Person
                    {
                        FirstName = pp[0], LastName = pp[1], Birthday_Day = pp[2], Birthday_Month = pp[3], Birthday_Year = pp[4], E_Mail = pp[5], Gender = pp[8], Mobil = pp[6], PassWord = pp[10], UserName = pp[9], Picture = pp[11], Telephon = pp[7], Sath_E_Dastresy = "1"
                    };

                    db01.person1.Add(per);
                    db01.SaveChanges();
                }
            }
        }
Exemple #2
0
        public void Add_Person_ByAdmin(List <string> pp)
        {
            using (var db01 = new ConnectingDB())
            {
                Person per = new Person
                {
                    FirstName = pp[0], LastName = pp[1], Birthday_Day = pp[2], Birthday_Month = pp[3], Birthday_Year = pp[4], E_Mail = pp[5], Gender = pp[9], Mobil = pp[6], PassWord = pp[11], UserName = pp[10], Picture = pp[12], Telephon = pp[7], Sath_E_Dastresy = pp[8]
                };

                db01.person1.Add(per);
                db01.SaveChanges();
            }
        }
        public void SaveToDB(List <Shoppingcart> shoppingcarts, string user, string pass, string PersonNamE, string PersoNID)
        {
            DBController dBController  = new DBController();
            bool         CorrectPerson = false;

            foreach (var item in shoppingcarts)
            {
                //1st condition:Is there this person in my DB or no??   2nd condition:Is this shopping cart for this person ???
                if (dBController.Checklogin_Customer(item.PersonUser, item.PersonPass) && item.PersonUser == user && item.PersonPass == pass)
                {
                    CorrectPerson = true;
                    break;
                }
            }

            if (CorrectPerson)
            {
                List <SaveShoppingCartToDB> saveShoppingCartToDBs1 = new List <SaveShoppingCartToDB>();
                SaveShoppingCartToDB        saveShoppingCartToDB   = new SaveShoppingCartToDB();

                foreach (var item in shoppingcarts)
                {
                    saveShoppingCartToDB.PersonID     = PersoNID;
                    saveShoppingCartToDB.PersonName   = PersonNamE;
                    saveShoppingCartToDB.ProductName  = item.ProductName;
                    saveShoppingCartToDB.ProductPrice = Convert.ToString(item.Price);
                    saveShoppingCartToDB.PersonUser   = user;
                    saveShoppingCartToDB.PersonPass   = pass;

                    saveShoppingCartToDBs1.Add(saveShoppingCartToDB);
                }

                using (ConnectingDB connectingDB = new ConnectingDB())
                {
                    foreach (var item in saveShoppingCartToDBs1)
                    {
                        connectingDB.saveShoppingCartToDBs.Add(item);
                    }
                    connectingDB.SaveChanges();
                }
            }
        }
Exemple #4
0
        public bool Checklogin_Admin(string user, string pass)
        {
            try
            {
                var db  = new ConnectingDB();
                var res = db.person1.Where(i => i.UserName == user && i.PassWord == pass).FirstOrDefault();

                if (res != null && res.Sath_E_Dastresy == "0")
                {
                    return(true);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #5
0
        //admin edit info of himself(herself):
        public void Edit_Person_ByAdmin(List <string> qq, string Old_Username, string Old_Password)
        {
            try
            {
                if (dBController.Checklogin_Admin(Old_Username, Old_Password))
                {
                    using (ConnectingDB connecting = new ConnectingDB())
                    {
                        var ss = connecting.person1.Where(k => k.UserName == Old_Username && k.PassWord == Old_Password).FirstOrDefault();
                        ss.FirstName       = qq[0];
                        ss.LastName        = qq[1];
                        ss.Birthday_Day    = qq[2];
                        ss.Birthday_Month  = qq[3];
                        ss.Birthday_Year   = qq[4];
                        ss.E_Mail          = qq[5];
                        ss.Mobil           = qq[6];
                        ss.Telephon        = qq[7];
                        ss.Gender          = qq[9];
                        ss.Picture         = qq[12];
                        ss.UserName        = qq[10];
                        ss.PassWord        = qq[11];
                        ss.Sath_E_Dastresy = qq[8];

                        connecting.person1.Attach(ss);
                        connecting.Entry(ss);
                        connecting.SaveChanges();
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #6
0
        public void Delete_Person(string us, string ps)
        {
            if (dBController.Checklogin_Admin(us, ps) || dBController.Checklogin_Customer(us, ps))
            {
                using (var db02 = new ConnectingDB())
                {
                    var tt = db02.person1.Where(a => a.UserName == us && a.PassWord == ps).FirstOrDefault();

                    int id = tt.ID;
                    //remove person:
                    db02.person1.Remove(tt);
                    //ordering ID number in database after deleting a person:
                    foreach (var item in db02.person1)
                    {
                        if (item.ID > id)
                        {
                            item.ID -= 1;
                        }
                    }

                    db02.SaveChanges();
                }
            }
        }