Esempio n. 1
0
        public ActionResult AddSupplier()
        {
            Supplier supplier = new Supplier();

            // get delivery methods SelectList for supplier
            ViewBag.DeliveryMethodID = new SelectList(Retriever.GetDeliveryMethods(), "DeliveryMethodId", "Name", null);

            return View(supplier);
        }
Esempio n. 2
0
        public ActionResult AddSupplier(Supplier supplier, HttpPostedFileBase upload)
        {
            ViewBag.DeliveryMethodID = new SelectList(Retriever.GetDeliveryMethods(), "DeliveryMethodId", "Name", null);

            if (upload == null)
            {
                ModelState.AddModelError("NoImage", "Upload supplier's image");
            }

            if (ModelState.IsValid)
            {
                Guid number = Guid.NewGuid();

                // assign upload to color and save on server
                FilePath image = new FilePath()
                {
                    FileType = FileType.supplierImage,
                    FileName = Path.GetFileName(number + "-" + upload.FileName),
                };

                supplier.FilePath = image;
                supplier.FilePathId = image.FilePathId;

                upload.SaveAs(Path.Combine(Server.MapPath("~/Content/Images/Suppliers"), image.FileName));

                // save changes
                repository.Add(supplier);
                image.Suppliers.Add(supplier);
                repository.Save();

                return RedirectToAction("Index");
            }

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