예제 #1
0
 public ActionResult Edit([Bind(Include = "tbGroupId,GroupName,Description,IsDisable")] tbGroup tbGroup)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbGroup).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("__Cms/Groups/Edit", tbGroup));
 }
예제 #2
0
        public ActionResult Create([Bind(Include = "tbUserId,Username,Fullname,Password,IsDisable")] tbUser tbUser, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                tbUser tbUserCheck = db.tbUsers.Where(p => p.Username == tbUser.Username).FirstOrDefault();
                if (tbUserCheck != null)
                {
                    ModelState.AddModelError("UserNameValid", "Tài khoản '" + tbUser.Username + "' đã tồn tại!!!");
                    return(View(tbUser));
                }

                tbUser.Password = DreamCMS.Encrypt.DHash.Encrypt(tbUser.Password);
                db.tbUsers.Add(tbUser);
                db.SaveChanges();

                // AVATAR
                if (file != null)
                {
                    if (HttpPostedFileBaseExtensions.IsImage(file))
                    {
                        string ext = Path.GetExtension(file.FileName).ToLower();
                        //string pic = Path.GetFileName(file.FileName);
                        string path = Path.Combine(Server.MapPath("~/Areas/Admin/upload/avatar"), tbUser.Username + ext);
                        // file is uploaded
                        file.SaveAs(path);

                        tbUser.AvatarUrl       = tbUser.Username + ext;
                        db.Entry(tbUser).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View("__Cms/Users/Create", tbUser));
        }