public ActionResult UpdateCustomer(CusPost cus) { using (DataContext db = new DataContext()) { Customer c = db.Customers.Where(x => x.Customer_ID == cus.userid).FirstOrDefault(); if (cus.username != null || cus.phone != null || cus.address != null) { c.customerName = cus.username; c.customerPhone = cus.phone; c.role = 3; c.sex = Convert.ToBoolean(cus.sex); if (Convert.ToBoolean(cus.sex) == true) { c.avatar = "avt_men.jpg "; } else { c.avatar = "avt_girl.jpg"; } c.customerAddress = cus.address; db.SaveChanges(); return(Json(new { mess__ = 1 })); } else { return(Json(new { mess__ = 0 })); } } }
public ActionResult Registration(CusPost cus) { using (DataContext db = new DataContext()) { ViewBag.GetRoles = (from r in db.Roles select r).ToList(); var checkEmailExist = (from u in db.Customers where u.customerEmail == cus.email select u).FirstOrDefault(); if (checkEmailExist == null) { Customer u = new Customer(); u.customerName = cus.username; u.customerEmail = cus.email; u.customerPhone = cus.phone; u.dayOfBirth = DateTime.Now; u.role = 3; //u.role = cus.role; u.password = Encode.CreateMD5(cus.password); u.sex = Convert.ToBoolean(cus.sex); if (Convert.ToBoolean(cus.sex) == true) { u.avatar = "avt_men.jpg "; } else { u.avatar = "avt_girl.jpg"; } u.customerAddress = cus.address; db.Customers.Add(u); db.SaveChanges(); return(Json(new { mess_ = 1 })); } else { return(Json(new { mess_ = 0 })); } } }