public ActionResult Register(RegisterViewModel register) { if (ModelState.IsValid) { if (!db.Users.Any(u => u.Email == register.Email.Trim().ToLower())) { Users user = new Users() { Email = register.Email, Password = FormsAuthentication.HashPasswordForStoringInConfigFile(register.Password, "MD5"), ActiveCode = Guid.NewGuid().ToString(), IsActive = false, RegisterDate = DateTime.Now, RoleID = 1, UserName = register.UserName }; db.Users.Add(user); db.SaveChanges(); //send Email string body = PartialToStringClass.RenderPartialView("ManageEmail", "ActivationEmail", user); SendEmail.Send(user.Email, "ایمیل فعال سازی ", body); //end send email return(View("SuccessRegister", user)); } else { ModelState.AddModelError("Email", "ایمیل وارد شده تکراری است"); } } return(View(register)); }
public ActionResult Create([Bind(Include = "ProductID,Title,ShortDescription,Text,Price,ImageName,CreateDate")] Products products) { if (ModelState.IsValid) { db.Products.Add(products); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(products)); }
public ActionResult Create([Bind(Include = "FeatureID,FeatureTitle")] Features features) { if (ModelState.IsValid) { db.Features.Add(features); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(features)); }
public ActionResult Create([Bind(Include = "GroupID,GroupTitle,ParentID")] Product_Groups product_Groups) { if (ModelState.IsValid) { db.Product_Groups.Add(product_Groups); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ParentID = new SelectList(db.Product_Groups, "GroupID", "GroupTitle", product_Groups.ParentID); return(View(product_Groups)); }
public ActionResult Create([Bind(Include = "UserID,RoleID,UserName,Email,Password,ActiveCode,RegisterDate,IsActive")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoleID = new SelectList(db.Roles, "RoleID", "RoleTitle", user.RoleID); return(View(user)); }
public ActionResult Create([Bind(Include = "GroupID,GroupTitle,ParentID")] Product_Groups product_Groups) { if (ModelState.IsValid) { db.Product_Groups.Add(product_Groups); db.SaveChanges(); return(PartialView("ListGroups", db.Product_Groups.Where(g => g.ParentID == null))); } ViewBag.ParentID = new SelectList(db.Product_Groups, "GroupID", "GroupTitle", product_Groups.ParentID); return(View(product_Groups)); }
public ActionResult Create([Bind(Include = "UserID,RoleID,UserName,Email,Password,ActiveCode,IsActive,RegisterDate")] Users users) { if (ModelState.IsValid) { users.RegisterDate = DateTime.Now; users.ActiveCode = Guid.NewGuid().ToString(); users.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(users.Password, "MD5"); db.Users.Add(users); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoleID = new SelectList(db.Roles, "RoleID", "RoleTitle", users.RoleID); return(View(users)); }
public ActionResult Payment() { int userId = db.Users.Single(u => u.UserName == User.Identity.Name).UserID; Orders order = new Orders() { UserID = userId, Date = DateTime.Now, IsFinaly = false }; db.Orders.Add(order); var listDetails = getListOrder(); foreach (var item in listDetails) { db.OrderDetails.Add(new OrderDetails() { Count = item.Count, OrderID = order.OrderID, Price = item.Price, ProductID = item.ProductID }); } db.SaveChanges(); //ToDo : Online Payment return(null); }
public ActionResult Register(RegisterViewModel register) { if (ModelState.IsValid) { if (this.IsCaptchaValid("Captcha is not valid")) { if (!IsUserNameExist(register.UserName)) { if (!IsEmailExist(register.Email)) { User user = new User() { Email = register.Email.Trim().ToLower(), IsActive = false, ActiveCode = Guid.NewGuid().ToString(), Password = FormsAuthentication.HashPasswordForStoringInConfigFile(register.Password, "MD5"), RoleID = 2, RegisterDate = DateTime.Now, UserName = register.UserName }; db.Users.Add(user); db.SaveChanges(); string Body = PartialToStringClass.RenderPartialView("EmailSender", "ActiveAccount", user); SendEmailGmail.Send(user.Email, "فعال سازی", Body); ViewBag.IsSuccess = true; } else { ModelState.AddModelError("Email", "ایمیل معتبر نمی باشد"); } } else { ModelState.AddModelError("UserName", "نام کاربری معتبر نمی باشد"); } } else { ModelState.AddModelError("CaptchaInputText", "Captcha is not valid"); } } return(View(register)); }
public ActionResult Create([Bind(Include = "SlideID,Title,ImageName,StartDate,EndDate,IsActive,Url")] Slider slider, HttpPostedFileBase imgUp) { if (ModelState.IsValid) { if (imgUp == null && !imgUp.IsImage()) { ModelState.AddModelError("ImageName", "لطفا تصویر را انتخاب کنید"); return(View(slider)); } slider.StartDate = DateTime.Now; slider.EndDate = DateTime.Now; slider.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(imgUp.FileName); imgUp.SaveAs(Server.MapPath("/Images/Slider/" + slider.ImageName)); db.Slider.Add(slider); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(slider)); }
public ActionResult Create([Bind(Include = "ProductID,Title,ShortDescription,Text,Price,ImageName,CreateDate")] Products products, List <int> selectedGroups, HttpPostedFileBase imageProduct, string tags) { if (ModelState.IsValid) { if (selectedGroups == null) { ViewBag.ErrorSelectedGroup = true; ViewBag.Groups = db.Product_Groups.ToList(); return(View(products)); } products.ImageName = "images.jpg"; if (imageProduct != null && imageProduct.IsImage()) { products.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imageProduct.FileName); imageProduct.SaveAs(Server.MapPath("/Images/ProductImages/" + products.ImageName)); ImageResizer img = new ImageResizer(); img.Resize(Server.MapPath("/Images/ProductImages/" + products.ImageName), Server.MapPath("/Images/ProductImages/Thumb/" + products.ImageName)); } products.CreateDate = DateTime.Now; db.Products.Add(products); foreach (int selectedGroup in selectedGroups) { db.Prodct_Selected_Groups.Add(new Prodct_Selected_Groups() { ProductID = products.ProductID, GroupID = selectedGroup }); } if (!string.IsNullOrEmpty(tags)) { string[] tag = tags.Split(','); foreach (string t in tag) { db.Product_Tags.Add(new Product_Tags() { ProductID = products.ProductID, Tag = t.Trim() }); } } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Groups = db.Product_Groups.ToList(); return(View(products)); }
public ActionResult ChangePassword(CahngePasswordViewModel change) { if (ModelState.IsValid) { var user = db.Users.Single(u => u.UserName == User.Identity.Name); string oldpasswordhash = FormsAuthentication.HashPasswordForStoringInConfigFile(change.OldPassword, "MD5"); if (user.Password == oldpasswordhash) { string hashNewPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(change.Password, "MD5"); user.Password = hashNewPassword; db.SaveChanges(); ViewBag.Success = true; } else { ModelState.AddModelError("OldPassword", "کلمه عبور فعلی درست نمی باشد"); } } return(View()); }