コード例 #1
0
        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());
            }
        }
コード例 #2
0
        // 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));
        }
コード例 #3
0
        /// <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();
        }
コード例 #4
0
        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");
            }
        }
コード例 #5
0
        public void MyTestInitialize()
        {
            this.target = new ServiceTypesLogics();

            this.providerServiceCategory1 = new ProviderServiceCategory
            {
                Active      = true,
                Crime       = true,
                Description = "Service Description",
                ID          = 1,
                Name        = "Test 1"
            };
            this.providerServiceCategory2 = new ProviderServiceCategory
            {
                Active      = true,
                Crime       = true,
                Description = "Service Description",
                ID          = 2,
                Name        = "Test 2"
            };
            this.providerServiceCategoryList = new List <ProviderServiceCategory>
            {
                this.providerServiceCategory1,
                this.providerServiceCategory2
            };
            this.categoryTest = new Category {
                Description = "Service Description", Name = "Test 1", Id = 1
            };
            this.serviceType1 = new ServiceType {
                Description = "Test Type 1", ID = 1, Name = "Type 1"
            };
            this.serviceType2 = new ServiceType {
                Description = "Test Type 2", ID = 2, Name = "Type 2"
            };

            this.serviceTypeList = new List <ServiceType> {
                this.serviceType1, this.serviceType2
            };
        }