public ActionResult Create(CategoryEditor catEditor)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var serviceInfo = new ServiceTypesLogics();
                    ViewBag.types = serviceInfo.GetServiceTypes().ToList().Select(x => new SelectListItem()
                    {
                        Value = x.Key.ToString(),
                        Text  = x.Value
                    });
                    return(View(catEditor));
                }

                CategoriesLogic catLogic = new CategoriesLogic();
                catEditor.State = ObjectStatus.ObjectState.Create; //Set the object's state to Create
                List <CategoryEditor> catEditList = new List <CategoryEditor>();
                catEditList.Add(catEditor);
                catLogic.EditCategories(catEditList);

                return(this.RedirectToAction("Index"));
            }
            catch
            {
                Console.WriteLine("Error creating new CategoryEditor");
                return(View());
            }
        }
        // GET: CatagoryEditor/Create
        public ActionResult Create()
        {
            var serviceInfo = new ServiceTypesLogics();

            ViewBag.types = serviceInfo.GetServiceTypes().ToList().Select(x => new SelectListItem()
            {
                Value = x.Key.ToString(),
                Text  = x.Value
            });
            CategoryEditor catEditor = new CategoryEditor();

            catEditor.Active = true;
            return(this.View(catEditor));
        }
        /// <summary>
        /// Gets all the data needed for the Create view and puts it in the ViewBag
        /// </summary>
        private void SetupViewBag()
        {
            var serviceInfo = new ServiceTypesLogics();

            ViewBag.types = serviceInfo.GetServiceTypes().ToList().Select(x => new SelectListItem()
            {
                Value = x.Key.ToString(),
                Text  = x.Value
            });
            ;
            var categories = this.dataLogics.GetWebsiteCategories();

            categories.Sort((category1, category2) => category1.Name.CompareTo(category2.Name));
            ViewBag.AllCategories = categories;

            this.BuildCountryList();
        }
        public void CreateTest()
        {
            var target = new ServiceTypesLogics();
            var serviceType1 = new ServiceType {  ID = 1, Name = "Type 1" };
            var serviceType2 = new ServiceType {  ID = 2, Name = "Type 2" };
            var serviceTypeList = new List<ServiceType> { serviceType1, serviceType2 };
            using (ShimsContext.Create())
            {
                ShimServiceTypesRepo.AllInstances.GetServiceTypes = repo => serviceTypeList;

                var response = target.GetServiceTypes();

                Assert.IsNotNull(response);
                Assert.AreEqual(serviceTypeList.Count, response.Count);

                Assert.IsTrue(response.ContainsKey(serviceTypeList[0].ID));
                Assert.AreEqual(serviceTypeList[0].Name, response[serviceTypeList[0].ID]);

                Assert.IsTrue(response.ContainsKey(serviceTypeList[1].ID));
                Assert.AreEqual(serviceTypeList[1].Name, response[serviceTypeList[1].ID]);
            }
            using (ShimsContext.Create())
            {
                ShimCategoriesLogic.AllInstances.GetCategories = access => categoryList;
                ShimCategoriesLogic.AllInstances.EditCategoriesListOfCategoryEditor = (access, cat) => true;
                CategoryEditorController controller = new CategoryEditorController();

                CategoryEditor sampleCategory = new CategoryEditor
                {
                    Name = "Name",
                    Description = "Description",
                    Active = true,
                    Crime = true
                };

                var result = controller.Create(sampleCategory);
                Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
                RedirectToRouteResult routeResult = result as RedirectToRouteResult;
                Assert.IsNotNull(routeResult);
                Assert.AreEqual(routeResult.RouteValues["action"], "Index");
            }
        }