Exemple #1
0
        public IHttpActionResult PuttAccount(int id, tAccount tAccount)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tAccount.ID)
            {
                return(BadRequest());
            }

            db.Entry(tAccount).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tAccountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // 尝试注册用户

                if (model.Password == model.ConfirmPassword)
                {
                    tAccount user = new tAccount()
                    {
                        UserName = model.UserName, Password = model.Password, Email = model.Email, RegisterTime = DateTime.Now
                    };
                    db.tAccounts.AddObject(user);
                    if (db.SaveChanges() > 0)
                    {
                        FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "服务器异常。");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "两次密码不匹配。");
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单

            return(View(model));
        }
Exemple #3
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (cl.checkRole(Session["userid_hcc"].ToString(), codeModule, 1))
     {
         if (txtAccount.Text.Trim().Equals(""))
         {
             Mess("Nhập tên tài khoản", "");
         }
         else
         {
             try
             {
                 tAccount ac = new tAccount();
                 ac.Username = txtAccount.Text.Trim().ToLower();
                 ac.Password = cl.MaHoa(txtPass.Text.Trim());
                 ac.FullName = txtName.Text.Trim();
                 ac.IsActive = ckActive.Checked;
                 ac.CreateAt = DateTime.Now;
                 db.tAccounts.InsertOnSubmit(ac);
                 db.SubmitChanges();
                 ResetControl();
                 LoadGrid();
                 Mess("Lưu thành công", "");
             }
             catch (Exception ax)
             {
                 Mess(ax.Message, "");
             }
         }
     }
     else
     {
         Mess("Bạn không có quyền sử dụng chức năng này", "/adhome");
     }
 }
Exemple #4
0
        public IHttpActionResult GettAccount(int id)
        {
            tAccount tAccount = db.tAccounts.Find(id);

            if (tAccount == null)
            {
                return(NotFound());
            }

            return(Ok(tAccount));
        }
Exemple #5
0
        public IHttpActionResult PosttAccount(tAccount tAccount)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tAccounts.Add(tAccount);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = tAccount.ID }, tAccount));
        }
Exemple #6
0
        public IHttpActionResult DeletetAccount(int id)
        {
            tAccount tAccount = db.tAccounts.Find(id);

            if (tAccount == null)
            {
                return(NotFound());
            }

            db.tAccounts.Remove(tAccount);
            db.SaveChanges();

            return(Ok(tAccount));
        }
Exemple #7
0
        public bool insertAccount(string us, string pw, string name, string email, bool sex, string birth, string phone, string add, string stt, int group, string note, int branch, int branchtype, out string mess)
        {
            mess = "";
            bool       ok  = false;
            clsProcess cls = new clsProcess();

            try
            {
                var u = new tAccount();
                u.Username = us;
                u.FullName = name;
                u.Password = cls.Encrypt(pw);
                u.Email    = email;
                u.Sex      = sex;
                if (birth != "")
                {
                    u.Birthday = DateTime.Parse(birth);
                }
                u.Phone        = phone;
                u.Address      = add;
                u.Status       = byte.Parse(stt);
                u.GroupUserId  = group;
                u.Note         = note;
                u.CreateAt     = DateTime.Now;
                u.CreateBy     = WindowsFormsApplication3.Form1.user_id;
                u.BranchTypeId = branchtype;
                u.BranchId     = branch;
                db.tAccounts.InsertOnSubmit(u);
                db.SubmitChanges();
                ok = true;
            }
            catch (Exception ax)
            {
                ok   = false;
                mess = ax.Message;
            }
            return(ok);
        }