예제 #1
0
        public ActionResult Create(Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                ViewBag.country = DropDownList <CountryMaster> .LoadItems(
                    ObjectSourceModel.GetCountry(), "CountryID", "CountryName");

                ViewBag.SupplierTypes = new SelectList(new[]
                {
                    new { ID = 1, trans = "Shipping Industry" },
                    new { ID = 2, trans = "Service Industry" },
                }, "ID", "trans", 1);
                var supplierMasterTypes = (from d in db.SupplierTypeMasters select d).ToList();
                ViewBag.SupplierType = DropDownList <SupplierTypeMaster> .LoadItems(
                    supplierMasterTypes, "SupplierTypeID", "SupplierType");

                var query = (from t in db.Suppliers where t.SupplierName == supplier.SupplierName select t).ToList();

                if (query.Count > 0)
                {
                    ViewBag.SuccessMsg = "Supplier name is already exist";
                    return(View());
                }

                supplier.SupplierID = ObjectSourceModel.GetMaxNumberSupplier();
                db.Suppliers.Add(supplier);
                db.SaveChanges();
                ViewBag.SuccessMsg = "You have successfully added Supplier.";
                return(View("Index", db.Suppliers.ToList()));
            }

            return(View(supplier));
        }