public ActionResult Register(FormCollection form) { if (ModelState.IsValid) { IwanttobuyCustomer iwanttobuyCustomer = new IwanttobuyCustomer(); iwanttobuyCustomer.CustomerName = form.Get("CustomerName"); iwanttobuyCustomer.CustomerSurname = form.Get("CustomerSurname"); iwanttobuyCustomer.Email = form.Get("Email"); iwanttobuyCustomer.PhoneNo = form.Get("PhoneNo"); iwanttobuyCustomer.Address = form.Get("Address"); iwanttobuyCustomer.TextPassword = form.Get("TextPassword"); byte[] encrypt = Encryption.Encrypt(iwanttobuyCustomer.TextPassword); iwanttobuyCustomer.Password = encrypt; iwanttobuyCustomer.CreateDate = DateTime.Now.AddHours(7); iwanttobuyCustomer.CustomerType = "C"; iwanttobuyCustomer.NoOfLogin = 0; db.IwanttobuyCustomers.Add(iwanttobuyCustomer); db.SaveChanges(); TempData["Message"] = String.Format("คุณ {0} {1} ลงทะเบียนเสร็จสมบูรณ์", iwanttobuyCustomer.CustomerName.ToString(), iwanttobuyCustomer.CustomerSurname.ToString()); TempData["Type"] = "success"; return(RedirectToAction("Index")); } return(View("Index")); }
public ActionResult DeleteConfirmed(int id) { IwanttobuyCustomer iwanttobuyCustomer = db.IwanttobuyCustomers.Find(id); db.IwanttobuyCustomers.Remove(iwanttobuyCustomer); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "CustomerPK,CustomerName,CustomerSurname,Email,Password,CustomerType,PhoneNo,Address,CreateDate,LastLoginDate,NoOfLogin")] IwanttobuyCustomer iwanttobuyCustomer) { if (ModelState.IsValid) { db.Entry(iwanttobuyCustomer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(iwanttobuyCustomer)); }
// GET: IwanttobuyCustomers/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IwanttobuyCustomer iwanttobuyCustomer = db.IwanttobuyCustomers.Find(id); if (iwanttobuyCustomer == null) { return(HttpNotFound()); } return(View(iwanttobuyCustomer)); }
public ActionResult Login(FormCollection form) { IwanttobuyCustomer iwanttobuyCustomer = new IwanttobuyCustomer(); iwanttobuyCustomer.Email = form.Get("LoginEmail"); iwanttobuyCustomer.TextPassword = form.Get("LoginPassword"); if (String.IsNullOrEmpty(iwanttobuyCustomer.Email) || String.IsNullOrEmpty(iwanttobuyCustomer.TextPassword)) { TempData["Message"] = "Username or Password is wrong"; TempData["Type"] = "error"; return(View("Index")); } string pwd = iwanttobuyCustomer.TextPassword.ToString(); iwanttobuyCustomer.Password = Encryption.Encrypt(iwanttobuyCustomer.TextPassword); iwanttobuyCustomer = db.IwanttobuyCustomers.Where(m => m.Email == iwanttobuyCustomer.Email && m.Password == iwanttobuyCustomer.Password).FirstOrDefault(); if (iwanttobuyCustomer == null) { TempData["Message"] = "Username or Password is wrong"; TempData["Type"] = "error"; return(View("Index")); } iwanttobuyCustomer.LastLoginDate = DateTime.Now.AddHours(7); iwanttobuyCustomer.NoOfLogin = (iwanttobuyCustomer.NoOfLogin == 0 ? 1 : Convert.ToInt32(iwanttobuyCustomer.NoOfLogin) + 1); iwanttobuyCustomer.TextPassword = pwd; db.Entry(iwanttobuyCustomer).State = EntityState.Modified; db.SaveChanges(); Session["user"] = iwanttobuyCustomer; TempData["Message"] = String.Format("ยินดีต้อนรับ คุณ {0} {1}", iwanttobuyCustomer.CustomerName.ToString(), iwanttobuyCustomer.CustomerSurname.ToString()); TempData["Type"] = "success"; return(View("Index")); }