public ActionResult CreateProduct(Models.Product p1, HttpPostedFileBase ImageProduct)
        {
            string imageName = "nophoto.png";

            if (ImageProduct != null)
            {
                imageName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(ImageProduct.FileName);
                ImageProduct.SaveAs(System.Web.HttpContext.Current.Server.MapPath("/MyPictures/" + imageName));
            }
            p1.ImageProduct = imageName;
            var product = db.Products.Add(p1);

            db.SaveChanges();
            List <Models.CategoryName> CategoryNames = new List <Models.CategoryName>();

            if (Session["CategoryNames"] != null)
            {
                Models.ProductWithCategory pwc = new Models.ProductWithCategory();
                CategoryNames = Session["CategoryNames"] as List <Models.CategoryName>;
                foreach (var item in CategoryNames)
                {
                    pwc.IdCategoryName = item.IdCategoryName;
                    pwc.IdProduct      = product.IdProduct;
                    db.ProductWithCategorys.Add(pwc);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("CreateProduct"));
        }
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            //if (ModelState.IsValid)
            //{
            using (var context = new Models.db())
            {
                var user = context.myusers.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                if (user != null)
                {
                    //you can encrypt password here, we are not doing it
                    user.Password = model.NewPassword;
                    //make resetpasswordcode empty string now
                    user.ResetPasswordCode = "";
                    //to avoid validation issues, disable it
                    context.Configuration.ValidateOnSaveEnabled = false;
                    context.SaveChanges();
                    message = "New password updated successfully";
                }
                //}
            }
            //else
            //{
            //    message = "Something invalid";
            //}
            ViewBag.Message = message;
            return(View(model));
        }
 public ActionResult Register(Models.MyUser u1)
 {
     if (db.myusers.Any(x => x.Email == u1.Email))
     {
         var alert = "ایمیل شما موجود است";
         return(Json(alert, JsonRequestBehavior.AllowGet));
     }
     else
     {
         var alert2 = "لطفا ایمیل خود را تایید کنید";
         u1.ConfirmEmail = false;
         u1.IdRole       = 1;
         var NewUser = db.myusers.Add(u1);
         db.SaveChanges();
         BuildEmailTemplate(u1.UserId);
         return(Json(alert2, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult EditProfile(Models.MyUser u1)
        {
            var user = db.myusers.FirstOrDefault(t => t.UserId == u1.UserId);

            user.Email      = u1.Email;
            user.NameFamily = u1.NameFamily;
            db.SaveChanges();
            return(View(user));
        }
Esempio n. 5
0
        public ActionResult AddToPayment(Models.Payment pa1)
        {
            var PayId = db.Payments.Add(pa1);

            db.SaveChanges();
            List <Models.Product> listproduct = new List <Models.Product>();

            if (Session["Cart"] != null)
            {
                PaymentDetail pd1 = new PaymentDetail();
                listproduct = Session["Cart"] as List <Models.Product>;
                foreach (var item in listproduct)
                {
                    pd1.IdProduct        = item.IdProduct;
                    pd1.ProductPrice     = item.Price;
                    pd1.NumbersOfProduct = item.NumbersOfProduct;
                    pd1.IdPayment        = PayId.IdPayment;
                    db.paymentdetails.Add(pd1);
                    db.SaveChanges();
                }
            }
            return(View());
        }
        public ActionResult ForgotPassword(string EmailID)
        {
            string resetCode = Guid.NewGuid().ToString();
            var    verifyUrl = "/Account/ResetPassword/" + resetCode;
            var    link      = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl);

            using (var context = new Models.db())
            {
                var getUser = (from s in context.myusers where s.Email == EmailID select s).FirstOrDefault();
                if (getUser != null)
                {
                    getUser.ResetPasswordCode = resetCode;

                    //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property

                    context.Configuration.ValidateOnSaveEnabled = false;
                    context.SaveChanges();

                    var subject = "Password Reset Request";
                    var body    = "Hi " + getUser.NameFamily + ", <br/> You recently requested to reset your password for your account. Click the link below to reset it. " +

                                  " <br/><br/><a href='" + link + "'>" + link + "</a> <br/><br/>" +
                                  "If you did not request a password reset, please ignore this email or reply to let us know.<br/><br/> Thank you";

                    SendEmail(getUser.Email, body, subject);

                    ViewBag.Message = "Reset password link has been sent to your email id.";
                }
                else
                {
                    ViewBag.Message = "User doesn't exists.";
                    return(View());
                }
            }

            return(View());
        }