コード例 #1
0
 public ActionResult Add(USER UserR, FormCollection form, HttpPostedFileBase Picture)
 {
     if (Check.checkUserAdd(UserR))
     {
         if (ModelState.IsValid || UserR.PASSWORD != null || !UserR.PASSWORD.Equals(""))
         {
             if (userModels.CheckEmail(UserR.EMAIL))
             {
                 //upload file
                 if (Picture != null && Picture.ContentLength > 0)
                 {
                     var       path      = Server.MapPath("~/Assets/Upload/User/");
                     ImgUpload imgUpload = new ImgUpload();
                     UserR.PICTURE = imgUpload.Upload(Picture, path);
                 }
                 if (this.Request.Form["ACTIVE"] != null)
                 {
                     UserR.ACTIVE = true;
                 }
                 else
                 {
                     UserR.ACTIVE = false;
                 }
                 if (userModels.AddItem(UserR) > 0)
                 {
                     Session["mes"] = "Thêm thành công!!!";
                 }
                 else
                 {
                     Session["mes_er"] = "Thêm thất bại!!!";
                 }
                 return(RedirectToAction("Index", "UserManager"));
             }
             else
             {
                 Session["mes_er"] = "Email đã đăng ký!!!";
             }
         }
     }
     ViewBag.ListRole = roleModels.GetAllItems();
     return(View(UserR));
 }