示例#1
0
        public ActionResult Create(UserSearchCreate value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var search = this.UserSearchService.Create();

            value.Validate();

            if (value.IsValid)
            {
                value.ValueToModel(search);

                this.UserSearchService.Insert(search);

                return RedirectToRoute(UsersRoutes.SearchIndex, new { id = search.Id });
            }

            value.CopyToModel(ModelState);

            IList<UserSearch> searches = null;

            if (base.Identity.IsAuthenticated())
            {
                searches = this.UserSearchService.GetAll(new UserSearchUserSpecification(base.Identity.Id));
            }

            value.Initialize(searches);

            return View(Views.Create, value);
        }
示例#2
0
        public void Test_UserSearchCreate_Validate()
        {
            var value = new UserSearchCreate
            {
                Save = true
            };

            value.Validate();

            Assert.AreEqual(1, value.Errors.Count, "Errors");
        }
示例#3
0
        public ActionResult Create(UserSearchCreate value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var search = this.UserSearchService.Create();
            var privilege = new UserSearchPrivilege();

            if (!privilege.CanCreate(search))
            {
                return NotAuthorized();
            }

            value.Validate();

            if (value.IsValid)
            {
                value.ValueToModel(search);

                this.UserSearchService.Insert(search);

                return base.RedirectToRoute(UsersAdministrationRoutes.SearchIndex, new { id = search.Id });
            }

            value.CopyToModel(ModelState);

            var searches = this.UserSearchService.GetAll(new UserSearchUserSpecification(base.Identity.Id));

            value.Initialize(searches);

            return base.View(Views.Create, value);
        }