Exemplo n.º 1
0
        /// <summary>
        /// 根据用户ID删除一个用户
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public string DeleteUser(string userID)
        {
            if (string.IsNullOrEmpty(userID))
            {
                return("false;UserID为空。");
            }

            UserDbContext udb  = new UserDbContext("ConnStr1");
            Users         data = new Users();

            data.UserID = userID;
            udb.DeleteUser(data);
            udb.SaveChanges();

            return("ok;删除成功。");
        }
Exemplo n.º 2
0
        public void Test()
        {
            var u = new User()
            {
                Uid   = "001",
                Email = null,
                Name  = "a"
            };

            Db.AddUser(u);
            Assert.True(Db.Users.FirstOrDefault(x => x.Uid == u.Uid) != null);
            Assert.True(Db.FindUser("001") != null);
            u.Name = "b";
            Db.UpdateUser(u);
            Assert.True(Db.FindUser("001").Name == "b");
            Db.DeleteUser(u);
            Assert.True(Db.FindUser("001") == null);
        }
Exemplo n.º 3
0
        public ActionResult UpdateUser(UserRegister data, string updateType)
        {
            if (string.IsNullOrEmpty(updateType))
            {
                updateType = "1";
            }

            UserDbContext uc    = new UserDbContext("ConnStr1");
            Users         data2 = null;

            try
            {
                switch (updateType)
                {
                case "1":
                    if (data != null)
                    {
                        data2 = (Users)data;
                        data  = (UserRegister)uc.AddUser(data2);
                        uc.SaveChanges();
                    }
                    else
                    {
                        data = new UserRegister();
                    }
                    break;

                case "2":
                    if (data == null)
                    {
                        throw new Exception("数据为空,无法更新。");
                    }
                    uc.ModifyUser(data);
                    uc.SaveChanges();
                    break;

                case "3":
                    if (data == null)
                    {
                        throw new Exception("数据为空,无法删除。");
                    }
                    uc.DeleteUser(data);
                    uc.SaveChanges();
                    break;

                default:
                    throw new Exception("更新类型出错。");
                }

                string script = MvcUT.ShowAlertAndHref(this, "更新成功", "UpdateUser");
                return(Content(script));
            }
            catch (Exception ex)
            {
                if (ex.Message != null)
                {
                }

                this.ViewBag.ErrMsg = MisBase.BaseUT.GetRootException(ex).Message;

                return(View(data));
            }
        }