کد RegisterView <h1 class='separator page_title'>فرم ثبت نام </h1>
@using (Html.BeginForm("Register", "Register", FormMethod.Post, new { @class = "frm_register", @id = "frm_register" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div>
<div>
@Html.LabelFor(model => model.UserFullName, htmlAttributes: new { })
<i class="fa fa-star"> </i>
@Html.TextBoxFor(model => model.UserFullName, new { @class = "txtbox", @placeholder = "نام و نام خانوادگی ", name = "namefamily" })
@Html.ValidationMessageFor(model => model.UserFullName, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "" })
<i class="fa fa-star"> </i>
@Html.TextBoxFor(model => model.UserName, new { @class = "txtbox", @placeholder = "نام کاربری ", name = "username" })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserEmail, htmlAttributes: new { @class = "" })
<i class="fa fa-star"> </i>
@Html.TextBoxFor(model => model.UserEmail, new { @class = "txtbox", @placeholder = "ایمیل ", name = "email" })
@Html.ValidationMessageFor(model => model.UserEmail, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserPassword, htmlAttributes: new { @class = "" })
<i class="fa fa-star"> </i>
@Html.TextBoxFor(model => model.UserPassword, new { @class = "txtbox", @placeholder = "رمز عبور ", name = "password" })
@Html.ValidationMessageFor(model => model.UserPassword, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserMobile, htmlAttributes: new { @class = "" })
<i class="fa fa-star"> </i>
@Html.TextBoxFor(model => model.UserMobile, new { @class = "txtbox", @placeholder = "تلفن همراه ", name = "mobile" })
@Html.ValidationMessageFor(model => model.UserMobile, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserAddress, htmlAttributes: new { @class = "" })
<i class="fa fa-star"> </i>
@Html.TextBoxFor(model => model.UserAddress, new { @class = "txtbox", @placeholder = "ادرس منزل ", name = "address" })
@Html.ValidationMessageFor(model => model.UserAddress, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserNationalCode, htmlAttributes: new { @class = "" })
<i class="fa fa-star"> </i>
@Html.TextBoxFor(model => model.UserNationalCode, new { @class = "txtbox", @placeholder = "کد ملی ", name = "natcode" })
@Html.ValidationMessageFor(model => model.UserNationalCode, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserCity, htmlAttributes: new { @class = "" })
<i class="fa fa-star"> </i>
@Html.TextBoxFor(model => model.UserCity, new { @class = "txtbox", @placeholder = " شهر سکونت", name = "city" })
@Html.ValidationMessageFor(model => model.UserCity, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserTel, htmlAttributes: new { @class = "" })
@Html.TextBoxFor(model => model.UserTel, new { @style = "",@class = "txtbox", @placeholder = "تلفن منزل ", name = "phone" })
@Html.ValidationMessageFor(model => model.UserTel, "", new { @class = "text-danger" })
</div>
<div>
@Html.LabelFor(model => model.UserPostalcode, htmlAttributes: new { @class = "" })
@Html.TextBoxFor(model => model.UserPostalcode, new { @style = "", @class = "txtbox", @placeholder = " کد پستی ", name = "postalcode" })
@Html.ValidationMessageFor(model => model.UserPostalcode, "", new { @class = "text-danger" })
</div>
<div>
<label>استان :</label>
<select name="State" class="select">
@{
Rep_Register repProvice = new Rep_Register();
foreach (var item in repProvice.GetProvince())
{
<option value="@item.ProvinceId">@item.ProvinceName</option>
}
}
</select>
</div>
<div class='full'>
<input type="submit" name='go_register' value="ثبت نام" class="threed_button">
</div>
</div>
}
--------------------------------------------------------------------------------------------------------------------------------------RegisterController: [HttpGet]
public ActionResult Register()
{
if (Session["User"] != null)
{
return RedirectToAction("Profile", "Profile");
}
else
{
return View();
}
}
[HttpPost]
public ActionResult Register(User u, int ProvinceId)
{
if (Session["User"] == null)
{
User Ouser = new User();
Ouser.UserAddress = u.UserAddress;
Ouser.UserCity = u.UserCity;
Ouser.UserEmail = u.UserEmail;
Ouser.UserEmail = u.UserFullName;
Ouser.UserFullName = u.UserMobile;
Ouser.UserMobile = u.UserName;
Ouser.UserNationalCode = u.UserNationalCode;
Ouser.UserPassword = u.UserPassword;
Ouser.UserPostalcode = u.UserPostalcode;
Ouser.UserRate = "0";
Ouser.UserRegistrationDate = System.DateTime.Now;
Ouser.UserTel = u.UserTel;
Ouser.RoleId = 0;
Ouser.ProvinceId = ProvinceId;
Ouser.IsUserActive = false;
db.Users.Add(Ouser);
if (Convert.ToBoolean(db.SaveChanges() > 0))
{
TempData["Message"] = ".ثبت نام شما با موفقیت انجام شد. لطفا به ایمیل خود مراجعه و روی لینک تایید کلیک نمایید";
EmailConfirmtion ec = new EmailConfirmtion();
ec.EmailConfirmationCreationDate = DateTime.Now;
ec.EmailConfirmationIsConfirmed = false;
ec.UserId = db.Users.OrderByDescending(c => c.UseId).FirstOrDefault().UseId;
db.EmailConfirmtions.Add(ec);
db.SaveChanges();
Email email = new Email();
email.SendEmail(db.Settings.FirstOrDefault().SMTP, db.Settings.FirstOrDefault().SettingEmail, db.Settings.FirstOrDefault().SettingPassword, Ouser.UserEmail, "فعالسازی حساب کاربری",
"کاربر گرامی " + u.UserName + "</br> برای فعالسازی اکانت کاربری خود در سایت " + db.Settings.FirstOrDefault().SettingSiteTitle +
" روی لینک زیر کلیک کنید </br> <a href='http://localhost:29703/Register/EmailConfirmation?Code=" + db.EmailConfirmtions.OrderByDescending(a => a.EmailConfirmationId).FirstOrDefault().EmailConfi rmationId + "'> لینک فعالسازی</a>");
return RedirectToAction("Message");
}
else
{
TempData["Message"] = "NotAdded";
return RedirectToAction("Message");
}
}
else
{
return RedirectToAction("Profile", "Profile");
}
} یک مشکل دیگر هم در رابطه با همین کد ها دارم، وقتی ازاطلاعات را در صفحه ثبت نام وارد می کنم علاوه و دکمه ثبت را می زنم با اروری مواجه می شن که ProvinceId نمی تونه null باشه در صورتیکه جدول مربوط به استان پرشده و استان را انتخاب می کنم