예제 #1
0
        public List <SelectListItem> GetManufacturers()
        {
            var manufacturerDropDownList = new List <SelectListItem>();

            manufacturerDropDownList.Insert(0, new SelectListItem()
            {
                Text = "Select Manufacturer", Value = string.Empty
            });

            try
            {
                var manufacturerList = _manufacturerManager.GetAll(c => true);

                foreach (var manufacturer in manufacturerList)
                {
                    var item = new SelectListItem()
                    {
                        Text = manufacturer.Code + "-" + manufacturer.Name, Value = manufacturer.Id.ToString()
                    };
                    manufacturerDropDownList.Add(item);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            return(manufacturerDropDownList);
        }
        public ActionResult Create(Manufacturer manufacturer)
        {
            //PartialMenuView();
            if (ModelState.IsValid && manufacturer != null)
            {
                ModelState.Clear();

                try
                {
                    if (_manufacturerManager.Add(manufacturer))
                    {
                        ViewBag.Msg = "Created successfully!";
                        return(View());
                    }
                }
                catch (Exception exception)
                {
                    int NameExist = _manufacturerManager.GetAll(c => c.Name.Equals(manufacturer.Name)).Count();

                    if (NameExist > 0)
                    {
                        manufacturer.Name = null;
                        ModelState.AddModelError("Name", "Manufacturer name already exists");
                    }

                    int ShortNameExits = _manufacturerManager.GetAll(c => c.Code == manufacturer.Code).Count();

                    if (ShortNameExits > 0)
                    {
                        manufacturer.Code = null;
                        ModelState.AddModelError("Code", "Code already exists");
                    }
                }
            }

            return(View(manufacturer));
        }
예제 #3
0
 public JsonResult ChecManufacturerNameForExist(ManufacturerViewModel model)
 {
     model.Name = model.Name.TrimStart(' ');
     model.Name = model.Name.TrimEnd(' ');
     return(Json(_manufacturerManager.GetAll().Where(c => c.Name == model.Name && c.Id != model.Id && c.CountryId == model.CountryId).ToList().Count <= 0, JsonRequestBehavior.AllowGet));
 }
예제 #4
0
        public ActionResult Index()
        {
            var manufacturers = _manufacturerManager.GetAll();

            return(View(manufacturers));
        }
예제 #5
0
 // GET: Manufacturers
 public ActionResult Index()
 {
     return(View(_manufacturerManager.GetAll()));
 }
예제 #6
0
 //GET
 public ActionResult Create()
 {
     ViewBag.Manufacturers = new SelectList(_manufacturerManager.GetAll().ToList(), "Id", "Name");
     return(View());
 }