Ejemplo n.º 1
0
        //Add to cart
        public ActionResult AddToCart(int?productId, int?userId)
        {
            if (userId != null)
            {
                //check if the user has a cart
                var hasCart = hasShoppingCart(userId);
                //Create a new cart for the user, if the user does not have a cart
                if (hasCart == false)
                {
                    var userCart = new ShoppingCart();
                    userCart.UserID      = userId ?? default(int);
                    userCart.DateCreated = DateTime.Now;
                    db.ShoppingCarts.Add(userCart);
                    db.SaveChanges();

                    ShoppingCart cart   = getCart(userId);
                    var          cartId = cart.ShoppingCartID;
                    Session["cartId"] = cartId;
                    return(RedirectToAction("AddProduct", "ShoppingCarts", new { cartId = cartId, productId = productId }));
                }
                //if the user has a cart, add the product to the cart!
                else
                {
                    ShoppingCart cart   = getCart(userId);
                    var          cartId = cart.ShoppingCartID;
                    Session["cartId"] = cartId;
                    return(RedirectToAction("AddProduct", "ShoppingCarts", new { cartId = cartId, productId = productId }));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Users"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "BikeTypeID,BikeType1")] BikeType bikeType)
        {
            if (ModelState.IsValid)
            {
                db.BikeTypes.Add(bikeType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bikeType));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "BikeStatusID,BikeStatusName,Notes")] BikeStatus bikeStatus)
        {
            if (ModelState.IsValid)
            {
                db.BikeStatuses.Add(bikeStatus);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bikeStatus));
        }
        public ActionResult Create([Bind(Include = "BikeMakeID1,Manufacturer,City,State")] BikeMakeID bikeMakeID)
        {
            if (ModelState.IsValid)
            {
                db.BikeMakeIDs.Add(bikeMakeID);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bikeMakeID));
        }
        public ActionResult Create([Bind(Include = "TireID,TireSize,Tubeless")] TireType tireType)
        {
            if (ModelState.IsValid)
            {
                db.TireTypes.Add(tireType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tireType));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //custom user registration
                    UserDetail newUserDetail = new UserDetail();
                    newUserDetail.UsersID   = user.Id;
                    newUserDetail.FirstName = model.FirstName;
                    newUserDetail.LastName  = model.LastName;

                    StoreFrontEntities1 entity = new StoreFrontEntities1();
                    entity.UserDetails.Add(newUserDetail);
                    entity.SaveChanges();

                    UserManager.AddToRole(user.Id, "Customer");
                    //var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                    //ViewBag.Link = callbackUrl;
                    //return View("DisplayEmail");
                    return(View("Login"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded) //
                {
                    //if we land here, the new AspnetUser account has been created
                    #region assign UserDetails during registration
                    UserDetail newUserDeets = new UserDetail();
                    newUserDeets.UserID       = user.Id;         //pulling id from aspnetusers tables
                    newUserDeets.FirstName    = model.FirstName; //model bc model is what is being pass in above in registermodelview
                    newUserDeets.LastName     = model.LastName;
                    newUserDeets.FavoriteBike = model.FavoriteBike;

                    //now save info to the database
                    StoreFrontEntities1 db = new StoreFrontEntities1();
                    db.UserDetails.Add(newUserDeets);
                    db.SaveChanges();
                    #endregion

                    //Send the user to thelogin page to login with their new account

                    return(View("Login"));
                }

                AddErrors(result);
            }

            return(View(model));
        }
Ejemplo n.º 8
0
        public ActionResult Create([Bind(Include = "ProductID,Price,MaskSizeID,StockStatusID,UnitsAvailable,MaskTypeID,MachineTypeID,ProductName,ProductDescription,ProductImage,CategoryID,ManufacturerID,IsFeatured")]
                                   Product product, HttpPostedFileBase productImage)
        {
            if (ModelState.IsValid)
            {
                string imgName = "no-image.png";

                if (productImage != null)
                {
                    imgName = productImage.FileName;
                    string ext = imgName.Substring(imgName.LastIndexOf('.'));

                    string[] goodExts = { ".jpg", ".jpeg", ".gif", ".png" };

                    if (goodExts.Contains(ext.ToLower()) && productImage.ContentLength <= 4194304)
                    {
                        imgName = Guid.NewGuid() + ext.ToLower();

                        string savePath       = Server.MapPath("~/Content/img/product/");
                        Image  convertedImage = Image.FromStream(productImage.InputStream);
                        int    maxImageSize   = 500;
                        int    maxThumbSize   = 100;

                        ImageService.ResizeImage(savePath, imgName, convertedImage, maxImageSize, maxThumbSize);
                    }
                    else
                    {
                        imgName = "no-image.png";
                    }
                }

                product.ProductImage = imgName;

                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaskSizeID     = new SelectList(db.MaskSizes, "MaskSizeID", "Size", product.MaskSizeID);
            ViewBag.StockStatusID  = new SelectList(db.StockStatus, "StockStatusID", "StockStatus", product.StockStatusID);
            ViewBag.MachineTypeID  = new SelectList(db.MachineTypes, "MachineTypeID", "MachineTypeName", product.MachineTypeID);
            ViewBag.MaskTypeID     = new SelectList(db.MaskTypes, "MaskTypeID", "MaskTypeName", product.MaskTypeID);
            ViewBag.CategoryID     = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
            ViewBag.ManufacturerID = new SelectList(db.Manufactures, "ManufacturerID", "ManufacturerName", product.ManufacturerID);
            return(View(product));
        }
Ejemplo n.º 9
0
 public ActionResult Register(User user)
 {
     if (ModelState.IsValid)
     {
         user.DateCreated  = DateTime.Now;
         user.IsAdmin      = false;
         user.DateModified = DateTime.Now;
         db.Users.Add(user);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("Create"));
 }
Ejemplo n.º 10
0
 public JsonResult AjaxCreate(Manufacture manufacture)
 {
     db.Manufactures.Add(manufacture);
     db.SaveChanges();
     return(Json(manufacture));
 }
Ejemplo n.º 11
0
 public JsonResult AjaxCreate(StockStatu stockStatu)
 {
     db.StockStatus.Add(stockStatu);
     db.SaveChanges();
     return(Json(stockStatu));
 }
Ejemplo n.º 12
0
 public JsonResult AjaxCreate(MaskSize maskSize)
 {
     db.MaskSizes.Add(maskSize);
     db.SaveChanges();
     return(Json(maskSize));
 }
Ejemplo n.º 13
0
        //ajax methods to replace the regular action methods

        #region Ajax Create

        public JsonResult AjaxCreate(MachineType machineType)
        {
            db.MachineTypes.Add(machineType);
            db.SaveChanges();
            return(Json(machineType));
        }
Ejemplo n.º 14
0
 public int Complete()
 {
     return(Context.SaveChanges());
 }
Ejemplo n.º 15
0
 public JsonResult AjaxCreate(Category category)
 {
     db.Categories.Add(category);
     db.SaveChanges();
     return(Json(category));
 }