示例#1
0
 public IActionResult CreateBuyer(UserBuyer uc)
 {
     _auc.Add(uc);
     _auc.SaveChanges();
     ViewBag.message = "The user is saved successfully";
     return(View());
 }
示例#2
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            using (MellorShopEntities1 db = new MellorShopEntities1())
            {
                string userName        = null;
                string userPhone       = null;
                string deleveryAddress = null;
                bool   check           = false;
                userName        = textBoxEnterName.Text;
                userPhone       = textBoxEnterPhone.Text;
                deleveryAddress = textBoxDelivAddress.Text;
                email           = textBoxEmail.Text;

                //get all users from the database
                userBayerfromDB = db.UserBuyer.ToList();
                //if there is already a customer with the same phone number, we get it ID
                foreach (var user in userBayerfromDB)
                {
                    if (user.NameUserBuyer == userName && user.ContactPhone == userPhone)
                    {
                        userID = user.ID_UserBuyer;
                        check  = true;
                        break;
                    }
                }
                if (check == false)
                {
                    UserBuyer userToAdd = new UserBuyer();
                    userToAdd.NameUserBuyer = userName;
                    userToAdd.ContactPhone  = userPhone;
                    db.UserBuyer.Add(userToAdd);
                    db.SaveChanges();
                    UserBuyer ub;
                    ub     = db.UserBuyer.FirstOrDefault(u => u.ContactPhone == userToAdd.ContactPhone) as UserBuyer;
                    userID = ub.ID_UserBuyer;
                }
                DialogResult = DialogResult.OK;
            }
        }