Exemplo n.º 1
0
        public ActionResult Create(Entity.User model)
        {
            #region Upload Picture                             // จัดการบันทึกรูปภาพ
            HttpPostedFileBase Image = Request.Files["Image"]; //อ่านภาพต้นฉบับ

            if (Image != null && Image.ContentLength > 0)
            {
                string filename = Path.GetFileName(Image.FileName);
                string SavePath = Server.MapPath("~/UploadPicture");
                if (!Directory.Exists(SavePath))
                {
                    Directory.CreateDirectory(SavePath);
                }

                Image.SaveAs(SavePath + "/" + filename);   //บันทึกไฟล์ภาพ
                model.Image = "UploadPicture/" + filename; //ชื่อไฟล์และพาท
            }
            #endregion
            if (ModelState.IsValid)
            {
                var dal = new DAL.UserDAL();
                var chk = dal.Chkuser(model);
                if (chk != null)
                {
                    Response.Write("<script> alert('มีชื่อผู้ใช้นี้แล้ว')</script>");
                }
                else
                {
                    var result = dal.CreateUser(model);
                    if (result)
                    {
                        Response.Write("<script> alert('ลงทะเบียนสำเร็จ')</script>");
                    }
                    return(RedirectToAction("UserList", "User"));
                }
                return(View());
            }
            return(View(model));
        }
 public ActionResult Signup(UserRegistrationViewModel Um)
 {
     //Model Validation
     if (!ModelState.IsValid)
     {
         return(View(Um));
     }
     else
     {
         //Registration ko code yaha lekhna parcha
         DAL.UserDAL ud = new DAL.UserDAL();
         if (ud.IfUserExists(Um.UserName))
         {
             ModelState.AddModelError("Exists", "Username already Exists.");
             return(View(Um));
         }
         else
         {
             ud.CreateUser(Um);
             return(RedirectToAction("Index", "Home"));
         }
     }
 }
Exemplo n.º 3
0
        public User CreateUser(UserInsert user)
        {
            User User = UserDAL.CreateUser(user);

            return(User);
        }