示例#1
0
        public async Task<ActionResult> EditProduct(string id)
        {
            try
            {
                ParseQuery<ParseObject> q = ParseObject.GetQuery("Product");
                ParseObject p = await q.GetAsync(id);

                Product product = new Product();
                product.ProductId = p.ObjectId;
                product.mTitle = p.Get<string>("mTitle");
                product.mPrice = p.Get<float>("mPrice");
                product.mQuantity = p.Get<float>("mQuantity");
                product.mManufacture = p.Get<string>("mManufacture");
                product.mSalePrice = p.Get<float>("mSalePrice");
                product.mOldPrice = p.Get<float>("mOldPrice");

                product.mScreenResolution = p.Get<string>("mScreenResolution");
                product.mScreenSize = p.Get<string>("mScreenSize");
                product.mCPU = p.Get<string>("mCPU");
                product.mRAM = p.Get<string>("mRAM");
                product.mROM = p.Get<string>("mROM");
                product.mMemoryCard = p.Get<string>("mMemoryCard");
                product.mCamera = p.Get<string>("mCamera");
                product.mSim = p.Get<string>("mSim");
                product.mOS = p.Get<string>("mOS");
                product.mPin = p.Get<string>("mPin");
                product.mWeight = p.Get<string>("mWeight");

                product.mSize = p.Get<string>("mSize");
                product.mConnectionPort = p.Get<string>("mConnectionPort");
                product.mGuarantee = p.Get<string>("mGuarantee");
                return View(product);
            }
            catch (ParseException e)
            {
                return View();
            }
           
        }
        public async Task<ActionResult> ProductsList()
        {
            ParseQuery<ParseObject> query = ParseObject.GetQuery("Product");
            IEnumerable<ParseObject> products = await query.FindAsync();

            List<Product> _products = new List<Product>();

            foreach (ParseObject p in products)
            {
                Product product = new Product();
                product.ProductId = p.ObjectId;
                product.mTitle = p.Get<string>("mTitle");
                product.mPrice = p.Get<float>("mPrice");
                product.mQuantity = p.Get<float>("mQuantity");
                product.mManufacture = p.Get<string>("mManufacture");
                product.salePrice = p.Get<float>("salePrice");
                product.oldPrice = p.Get<float>("oldPrice");

                _products.Add(product);
            }

            return View(_products);
        }
示例#3
0
        public async Task<ActionResult> ProductsList()
        {
            ParseQuery<ParseObject> query = ParseObject.GetQuery("Product");

            IEnumerable<ParseObject> products = await query.FindAsync();

            List<Product> _products = new List<Product>();

            foreach (ParseObject p in products)
            {
                Product product = new Product();


                product.mTitle = p.Get<string>("mTitle");
                product.mPrice = p.Get<float>("mPrice");
                product.mQuantity = p.Get<float>("mQuantity");
                product.mManufacture = p.Get<string>("mManufacture");
                product.mSalePrice = p.Get<float>("mSalePrice");
                product.mOldPrice = p.Get<float>("mOldPrice");

                product.mScreenResolution = p.Get<string>("mScreenResolution");
                product.mScreenSize = p.Get<string>("mScreenSize");
                product.mCPU = p.Get<string>("mCPU");
                product.mRAM = p.Get<string>("mRAM");
                product.mROM = p.Get<string>("mROM");
                product.mMemoryCard = p.Get<string>("mMemoryCard");
                product.mCamera = p.Get<string>("mCamera");
                product.mSim = p.Get<string>("mSim");
                product.mOS = p.Get<string>("mOS");
                product.mPin = p.Get<string>("mPin");
                product.mWeight = p.Get<string>("mWeight");

                product.mSize = p.Get<string>("mSize");
                product.mConnectionPort = p.Get<string>("mConnectionPort");
                product.mGuarantee = p.Get<string>("mGuarantee");
                _products.Add(product);


            }

            return View(_products);
        }
示例#4
0
        public ActionResult Create()
        {
            Product newproduct = new Product();

            // set every size default as product size in checkboxes
            newproduct.Sizes = new List<Size>();
            PopulateAssignedSizeData(newproduct);

            ViewBag.CategoryId = new SelectList(Retriever.GetCategories(), "CategoryId", "CategoryName", null);
            ViewBag.ColorId = new SelectList(Retriever.GetColors(), "ColorId", "ColorName", null);

            return View(newproduct);
        }
示例#5
0
        /// <summary>
        /// mark product size checkboxes in view
        /// </summary>
        /// <param name="product"> specified product </param>
        private void PopulateAssignedSizeData(Product product)
        {
            DbSet<Size> allSizes = db.Sizes;
            HashSet<int> productSizes = new HashSet<int>(product.Sizes.Select(s => s.SizeId));
            List<SizeChoiceViewModel> viewModel = new List<SizeChoiceViewModel>();

            if (productSizes == null)
            {
                ModelState.AddModelError("NoSelectedSize", "Select product's size.");
            }
            else
            {
                foreach (Size size in allSizes)
                {
                    viewModel.Add(new SizeChoiceViewModel
                    {
                        SizeId = size.SizeId,
                        Assigned = productSizes.Contains(size.SizeId)
                    });
                }
                ViewBag.Sizes = viewModel;
            }
        }
示例#6
0
        /// <summary>
        /// update product sizes
        /// </summary>
        /// <param name="selectedSizes"> list of sizes </param>
        /// <param name="product"> product with updated sizes </param>
        private void UpdateProductSizes(string[] selectedSizes, Product product)
        {
            if (selectedSizes == null)
            {
                product.Sizes = new List<Size>();
                return;
            }

            HashSet<string> selectedSizesHS = new HashSet<string>(selectedSizes);
            HashSet<int> productSizes = new HashSet<int>(product.Sizes.Select(s => s.SizeId));

            foreach (Size size in db.Sizes)
            {
                if (selectedSizesHS.Contains(size.SizeId.ToString()))
                {
                    if (!productSizes.Contains(size.SizeId))
                    {
                        product.Sizes.Add(size);
                    }
                }
                else
                {
                    if (productSizes.Contains(size.SizeId))
                    {
                        product.Sizes.Remove(size);
                    }
                }
            }
        }
示例#7
0
        public async Task<ActionResult> Create(Product newproduct, IEnumerable<HttpPostedFileBase> uploads, string[] selectedSizes)
        {
            // remake if something went wrong
            ViewBag.CategoryId = new SelectList(Retriever.GetCategories(), "CategoryId", "CategoryName", null);
            ViewBag.ColorId = new SelectList(Retriever.GetColors(), "ColorId", "ColorName", null);

            if (ModelState.IsValid)
            {
                // assign sizes to product
                newproduct.Sizes = new List<Size>();

                foreach (string size in selectedSizes)
                {
                    Size sizeToAdd = db.Sizes.Find(int.Parse(size));
                    newproduct.Sizes.Add(sizeToAdd);
                }

                // set product images list
                newproduct.FilePaths = new List<FilePath>();

                foreach (HttpPostedFileBase upload in uploads)
                {
                    // check each file upload
                    // if any exists add this to product images list,
                    // save on server
                    if (upload != null && upload.ContentLength > 0)
                    {
                        FilePath photo = new FilePath()
                        {
                            FileName = Guid.NewGuid().ToString() + Path.GetExtension(upload.FileName),
                            FileType = FileType.Photo
                        };

                        newproduct.FilePaths.Add(photo);
                        upload.SaveAs(Path.Combine(Server.MapPath("~/Content/Images"), photo.FileName));
                    }
                }

                // calculate product price
                if (newproduct.Discount > 0)
                {
                    newproduct.Price = newproduct.NormalPrice - newproduct.NormalPrice * ((decimal)newproduct.Discount / 100);
                }
                else
                {
                    newproduct.Price = newproduct.NormalPrice;
                }

                // set create date and save changes
                newproduct.CreateDate = DateTime.Now;
                db.Products.Add(newproduct);
                await db.SaveChangesAsync();

                // set confirmation message to Index() View
                TempData["message"] = string.Format("{0} has been created.", newproduct.ProductName);

                return RedirectToAction("Index");
            }

            // return if invalid
            return View(newproduct);
        }