public ActionResult CreateProduct(TeaProduct tea, HttpPostedFileBase uploadedImageFile)
        {
            UploadedImage(tea, uploadedImageFile);
            dbContext.TeaProducts.Add(tea);
            dbContext.SaveChanges();

            List <TeaProduct> teaProducts = dbContext.TeaProducts.ToList();

            return(RedirectToAction("ViewProducts"));
        }
        public override ProductBase Create()
        {
            TeaProduct teaProduct = null;

            if (ValidateProduct())
            {
                teaProduct = new TeaProduct(Name);
                Availability--;
            }

            return(teaProduct);
        }
        private void UploadedImage(TeaProduct tea, HttpPostedFileBase uploadedImageFile)
        {
            string fileName = string.Empty;

            if (uploadedImageFile != null)
            {
                fileName          = System.IO.Path.GetFileName(uploadedImageFile.FileName);
                tea.ImageFileName = fileName;

                string imageFilePathOnServer = System.IO.Path.Combine(Server.MapPath("~/UploadedFiles"), fileName);
                uploadedImageFile.SaveAs(imageFilePathOnServer);
            }
        }
Esempio n. 4
0
        //Actually you can remove all the items directly
        public ActionResult RemoveFromCart(int recordId, int productId, string returnUrl)
        {
            //Find the cart
            string id = User.Identity.GetUserId();

            ShoppingRecordViewModel cart = new ShoppingRecordViewModel();
            List <ShRecord>         list = dbContext.ShRecords.Where(m => m.UserId == id).ToList();

            foreach (var record in list)
            {
                if (!record.IsCompleted)
                {
                    cart.recordCollection.Add(record);
                }
            }

            //make sure product is in the database, otherwise will make an error
            TeaProduct      product        = dbContext.TeaProducts.FirstOrDefault(m => m.ID == productId);
            List <ShRecord> deletedRecords = dbContext.ShRecords.Where(m => m.ID == recordId).ToList();
            ShRecord        deletedRecord  = new ShRecord();

            foreach (var record in deletedRecords)
            {
                if (!record.IsCompleted)
                {
                    deletedRecord = record;
                    break;
                }
            }

            if (product != null && deletedRecords != null)
            {
                cart.RemoveLine(product);
                dbContext.Entry(deletedRecord).State = System.Data.Entity.EntityState.Deleted;
                dbContext.SaveChanges();
            }

            return(RedirectToAction("Index", new { id, returnUrl }));
        }
Esempio n. 5
0
        public ActionResult AddToCart(int productId, string returnUrl, decimal finalPrice, int quantity)
        {
            if (Request.IsAuthenticated)
            {
                TeaProduct product           = dbContext.TeaProducts.FirstOrDefault(m => m.ID == productId);
                ShoppingRecordViewModel cart = GetCart();

                if (product != null)
                {
                    cart.AddItem(dbContext, product, finalPrice, quantity, User.Identity.GetUserId());
                }

                string id = User.Identity.GetUserId();

                //can only pass int or string
                return(RedirectToAction("Index", new { id, returnUrl }));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
        public ActionResult Edit(int id)
        {
            TeaProduct tea = dbContext.TeaProducts.FirstOrDefault(m => m.ID == id);

            return(View(tea));
        }