Exemplo n.º 1
0
        public ActionResult SaveRegisterDetails(Register registerDetails)
        {
            //We check if the model state is valid or not. We have used DataAnnotation attributes.
            //If any form value fails the DataAnnotation validation the model state becomes invalid.
            if (ModelState.IsValid)
            {
                //create database context using Entity framework
                using (var databaseContext = new LoginRegistrationInMVCEntities1())
                {
                    //If the model state is valid i.e. the form values passed the validation then we are storing the User's details in DB.
                    RegisterUser reglog = new RegisterUser();

                    //Save all details in RegitserUser object

                    reglog.FirstName = registerDetails.FirstName;
                    reglog.LastName  = registerDetails.LastName;
                    reglog.Email     = registerDetails.Email;
                    reglog.Password  = registerDetails.Password;


                    //Calling the SaveDetails method which saves the details.
                    databaseContext.RegisterUsers.Add(reglog);
                    databaseContext.SaveChanges();
                }

                ViewBag.Message = "User Details Saved";
                return(View("Register"));
            }
            else
            {
                //If the validation fails, we are returning the model object with errors to the view, which will display the error messages.
                return(View("Register", registerDetails));
            }
        }
        public ActionResult Index(HttpPostedFileBase postedFile, int price, int Category)
        {
            //Extract Image File Name.
            string fileName = System.IO.Path.GetFileName(postedFile.FileName);

            //Set the Image File Path.
            string filePath = "~/UploadImageFile/" + fileName;

            //Save the Image File in Folder.
            postedFile.SaveAs(Server.MapPath(filePath));

            //Insert the Image File details in Table.


            entities.Product_.Add(new Product_
            {
                Name       = fileName,
                Image      = filePath,
                Price      = price,
                Ctegory_ID = Category
            });

            entities.SaveChanges();

            //Redirect to Index Action.
            return(RedirectToAction("Index"));
        }
        public ActionResult ordersList()
        {
            int customerId = entities.RegisterUsers.Where(x => x.Email == System.Web.HttpContext.Current.User.Identity.Name).FirstOrDefault().Id;

            if (Session["cart"] != null)
            {
                var cart = (List <Item>)Session["cart"];
                foreach (var item in cart)
                {
                    entities.Orders.Add(new Order
                    {
                        OrderDate   = DateTime.Now,
                        Customer_ID = customerId,
                        Name        = item.Product.Name,
                        Price       = item.Product.Price,
                        Category_ID = item.Product.Ctegory_ID
                    });

                    entities.SaveChanges();
                }
            }
            Session["cart"] = null;
            return(RedirectToAction("ProceedToOrder"));
        }