Esempio n. 1
0
 public ActionResult Delete(string id)
 {
     try
     {
         var             db     = new TextEntities();
         List <UserInfo> dbInfo = db.UserInfo.ToList();
         db.UserInfo.Remove(dbInfo[int.Parse(id)]);
         db.SaveChanges();
         return(RedirectToAction("UserList"));
     }
     catch
     {
         ViewData["Message"] = "刪除失敗了唷!";
         return(View("UserList"));
     }
 }
Esempio n. 2
0
        public ActionResult Create(UserInfo info)
        {
            var             db          = new TextEntities();
            List <UserInfo> dbInfo      = db.UserInfo.ToList();
            var             newuserinfo = new UserInfo();

            foreach (UserInfo theinfo in dbInfo)
            {
                if (info.UserID.Equals(theinfo.UserID))
                {
                    ViewData["Message"] = "客戶編號重複,請更改編號!";
                    return(View());
                }
            }
            newuserinfo = info;
            db.UserInfo.Add(newuserinfo);
            db.SaveChanges();
            return(RedirectToAction("UserList"));
        }
Esempio n. 3
0
        public ActionResult Details(string id, UserInfo info)
        {
            var             db     = new TextEntities();
            List <UserInfo> dbInfo = db.UserInfo.ToList();

            try
            {
                dbInfo[int.Parse(id)].UserID   = info.UserID;
                dbInfo[int.Parse(id)].UserName = info.UserName;
                dbInfo[int.Parse(id)].Phone    = info.Phone;
                dbInfo[int.Parse(id)].Email    = info.Email;
                db.SaveChanges();
                return(RedirectToAction("UserList"));
            }
            catch
            {
                ViewData["Message"] = "修改出錯了唷!";
                return(RedirectToAction("Edit"));
            }
        }