コード例 #1
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new CustomerOrder();

            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(order));
                }
                else
                {
                    order.Email       = User.Identity.Name;
                    order.DateCreated = DateTime.Now;

                    db.CustomerOrders.Add(order);
                    db.SaveChanges();

                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    db.SaveChanges();//we have received the total amount lets update it

                    return(RedirectToAction("Complete", new { id = order.Id }));
                }
            }
            catch (Exception ex)
            {
                ex.InnerException.ToString();
                return(View(order));
            }
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "ProductId,ProductName,CategoryId,Description,ProductImage,Price")] Product product)
        {
            var fileSavePath = "";

            if (ModelState.IsValid)
            {
                var uniqueName = "";
                if (Request.Files["Image"] != null)
                {
                    var file = Request.Files["Image"];
                    if (file.FileName != "")
                    {
                        var ext = System.IO.Path.GetExtension(file.FileName);
                        // generate a unique name using guid
                        uniqueName = Guid.NewGuid().ToString() + ext;
                        var rootPath = Server.MapPath("~/Content/images");
                        fileSavePath = System.IO.Path.Combine(rootPath, uniqueName);
                        file.SaveAs(fileSavePath);
                    }
                }
                product.ProductImage = fileSavePath;
                product.CreatedDate  = DateTime.Now;
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CateegoryId", "CategoryName", product.CategoryId);
            return(View(product));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "CateegoryId,CategoryName,IsActive,IsDelete")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
コード例 #4
0
        public ActionResult VerifyAccount(String id) // from id i will get the activation code fromn the link which we have sent to the user email id this is means activation code
        {
            bool status = false;

            using (Shopping_Store_DataBaseEntities sd = new Shopping_Store_DataBaseEntities())
            {
                sd.Configuration.ValidateOnSaveEnabled = false; // this line i have added to avoid confirm password doesnot match issue

                var v = sd.Users.Where(a => a.ActivationKey == new Guid(id)).FirstOrDefault();

                // if link is valid then v is not null
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    sd.SaveChanges();
                    status = true;
                }
                else
                {
                    ViewBag.message = "Invalid request";
                }
            }
            ViewBag.Status = status;

            return(View());
        }
コード例 #5
0
        //for automatic binding we use bind exclude
        public ActionResult Signup([Bind(Exclude = "IsEmailVerified,ActivationKey")] User user)
        {
            bool   status = false;
            string message;

            //model validation
            if (ModelState.IsValid)
            {
                #region //email is already exist or validation of email

                var isExist = IsEmailExist(user.EmailId);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }

                #endregion


                #region  generate activation key

                user.ActivationKey = Guid.NewGuid();

                #endregion

                //password hashing for security (not saving password in our db and hash value is stored in our db)

                #region

                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); //to avoid confirm password validation issues

                #endregion

                //to avoid validation again on save changes i use
                user.IsEmailVerified = false;

                #region save data in our database

                using (Shopping_Store_DataBaseEntities sd = new Shopping_Store_DataBaseEntities())
                {
                    user.IsAdmin = false;
                    sd.Users.Add(user);
                    sd.SaveChanges();

                    //send email to user
                    SendVeificationLinkEmail(user.EmailId, user.ActivationKey.ToString());
                    message =
                        "Registration is sucessfully done!.Account activation link has been send to your email id " +
                        user.EmailId;
                    status = true;
                }

                #endregion
            }
            else
            {
                message = "Invalid request";
            }



            ViewBag.Message = message;
            ViewBag.Status  = status;



            return(View(user));
        }