Exemplo n.º 1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------//
        //------------------------------------------------------------Function---------------------------------------------------------------------//
        //-----------------------------------------------------------------------------------------------------------------------------------------//

        public bool AddUserData(FormUserData data)
        {
            try
            {
                UserData user = new UserData();
                user.account  = data.account;
                user.password = data.password1;
                user.city     = data.city;
                user.village  = data.village;
                user.address  = data.address;
                db.UserData.Add(user);
                db.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public ActionResult Register(FormUserData data)
        {
            FormDataModel model = new FormDataModel();

            if (string.IsNullOrWhiteSpace(data.password1) || data.password1 != data.password2)
            {
                model.Cities = db.City.ToList();
                if (!string.IsNullOrWhiteSpace(data.city))
                {
                    model.villages = db.Village.Where(x => x.CityId == data.city).ToList();
                }
                model.userData = data;
                ViewBag.Msg    = "密碼輸入錯誤";
                return(View(model));
            }
            else
            {
                try
                {
                    UserData user = new UserData();
                    user.account  = data.account;
                    user.password = data.password1;
                    user.city     = data.city;
                    user.village  = data.village;
                    user.address  = data.address;
                    db.UserData.Add(user);
                    db.SaveChanges();
                    Response.Redirect("~/Main/Login");
                    return(new EmptyResult());
                }
                catch (Exception e)
                {
                    ViewBag.Msg = e;
                    return(View(model));
                }
            }
        }
Exemplo n.º 3
0
 public ActionResult Register(FormUserData data)
 {
     if (string.IsNullOrWhiteSpace(data.password1) || data.password1 != data.password2)
     {
         List <City>    cityList    = db.City.ToList();
         List <Village> villageList = new List <Village>();
         if (!string.IsNullOrWhiteSpace(data.city))
         {
             villageList = db.Village.Where(x => x.CityId == data.city).ToList();
         }
         ViewBag.CityList    = cityList;
         ViewBag.VillageList = villageList;
         ViewBag.Msg         = "密碼輸入錯誤";
         return(View(data));
     }
     else
     {
         try
         {
             UserData user = new UserData();
             user.account  = data.account;
             user.password = data.password1;
             user.city     = data.city;
             user.village  = data.village;
             user.address  = data.address;
             db.UserData.Add(user);
             db.SaveChanges();
             Response.Redirect("~/Home/Login");
             return(new EmptyResult());
         }
         catch
         {
             ViewBag.Msg = "註冊失敗...";
             return(View(data));
         }
     }
 }