예제 #1
0
        public JsonResult Edit(MemberCommand model)
        {
            if (ModelState.IsValid)
            {
                if (MemberManager.Find(x => x.Email.ToLower() == model.Email.ToLower() && x.Id != model.Id) != null)
                {
                    ModelState.AddModelError(nameof(MemberCommand.Email), "Bu e-posta zaten kayıtlıdır.");
                }
                else
                {
                    Member member = MemberManager.Find(x => x.Id == model.Id);
                    Mapper.Map(model, member);
                    MemberManager.Update(member);

                    return(Json(new JsonResultObject <string>()
                    {
                        ResultMessage = "Güncelleme yapılmıştır."
                    }));
                }
            }

            JsonResultObject <List <string> > result =
                new JsonResultObject <List <string> >()
            {
                HasError      = true,
                ErrorMessages = ModelState.GetExceptionMessageList()
            };

            return(Json(result));
        }
예제 #2
0
        public JsonResult Create(MemberCommand model)
        {
            if (ModelState.IsValid)
            {
                if (MemberManager.Find(x => x.Email.ToLower() == model.Email.ToLower()) != null)
                {
                    ModelState.AddModelError(nameof(MemberCommand.Email), "Bu e-posta zaten kayıtlıdır.");
                }
                else
                {
                    Member member = Mapper.Map <Member>(model);
                    MemberManager.Insert(member);

                    return(Json(new JsonResultObject <string>()
                    {
                        ResultMessage = "Kayıt yapılmıştır."
                    }));
                }
            }

            JsonResultObject <List <string> > result =
                new JsonResultObject <List <string> >()
            {
                HasError      = true,
                ErrorMessages = ModelState.GetExceptionMessageList()
            };

            return(Json(result));
        }
예제 #3
0
        // GET: Member/Create
        public PartialViewResult Edit(int id)
        {
            Member        member = MemberManager.Find(x => x.Id == id);
            MemberCommand model  = Mapper.Map <MemberCommand>(member);

            return(base.PartialView("_EditMember", model));
        }
예제 #4
0
        public void Member_Execute_ReturnsEmpty()
        {
            var command       = new MemberCommand(_console, LoggerMock.GetLogger <MemberCommand>().Object);
            var resultMessage = command.Execute();

            Assert.Equal("", resultMessage);
        }
예제 #5
0
        public void Should_Process_ValueType_Variable()
        {
            Specification <int> specification = s => s;

            var command = new MemberCommand <SomeModel, int>(m => m.SomeValueVariable, specification);

            var blockBuilder = command.GetScopeBuilder();

            var buildingContext = Substitute.For <IScopeBuilderContext>();

            buildingContext.GetOrRegisterSpecificationScope(Arg.Any <Specification <int> >()).Returns(666);

            var block = blockBuilder.Build(buildingContext);

            block.Should().BeOfType <MemberCommandScope <SomeModel, int> >();

            var modelBlock = (MemberCommandScope <SomeModel, int>)block;

            modelBlock.Path = "SomeValueVariable";
            modelBlock.GetMemberValue.Should().BeOfType <Func <SomeModel, int> >();

            var someModel = new SomeModel()
            {
                SomeValueVariable = 777
            };

            var memberValue = modelBlock.GetMemberValue(someModel);

            memberValue.Should().Be(777);
        }
예제 #6
0
        public void Should_Process_Reference_Property()
        {
            Specification <object> specification = s => s;

            var command = new MemberCommand <SomeModel, object>(m => m.SomeReferenceProperty, specification);

            var blockBuilder = command.GetScopeBuilder();

            var buildingContext = Substitute.For <IScopeBuilderContext>();

            buildingContext.GetOrRegisterSpecificationScope(Arg.Any <Specification <object> >()).Returns(666);

            var block = blockBuilder.Build(buildingContext);

            block.Should().BeOfType <MemberCommandScope <SomeModel, object> >();

            var modelBlock = (MemberCommandScope <SomeModel, object>)block;

            modelBlock.Path = "SomeReferenceProperty";
            modelBlock.GetMemberValue.Should().BeOfType <Func <SomeModel, object> >();

            var someModel = new SomeModel()
            {
                SomeReferenceProperty = new object()
            };

            var memberValue = modelBlock.GetMemberValue(someModel);

            memberValue.Should().BeSameAs(someModel.SomeReferenceProperty);
        }
예제 #7
0
        // GET: Member/Edit/5
        public ActionResult Edit(int id)
        {
            Member        member = MemberManager.Find(x => x.Id == id);
            MemberCommand model  = Mapper.Map <MemberCommand>(member);

            return(View(model));
        }
예제 #8
0
            protected override Tuple <T1, T2>[] Read(long count, RedisReader reader)
            {
                var array = new Tuple <T1, T2> [count / 2];

                for (int i = 0; i < count; i += 2)
                {
                    array[i / 2] = MemberCommand.Parse(reader);
                }
                return(array);
            }
예제 #9
0
        public void Should_Get_BlockBuilder()
        {
            Specification <object> specification = s => s;

            var command = new MemberCommand <SomeModel, object>(m => m.SomeReferenceProperty, specification);

            var blockBuilder = command.GetScopeBuilder();

            blockBuilder.Should().NotBeNull();
        }
예제 #10
0
        public ActionResult Create(MemberCommand model)
        {
            if (ModelState.IsValid)
            {
                Member member = Mapper.Map <Member>(model);
                MemberManager.Insert(member);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
예제 #11
0
        public void Should_ThrowException_When_MemberIsFunction_ReturningReferenceType()
        {
            Specification <object> specification = s => s;

            var command         = new MemberCommand <SomeModel, object>(m => m.SomeFunctionReturningReference(), specification);
            var blockBuilder    = command.GetScopeBuilder();
            var buildingContext = Substitute.For <IScopeBuilderContext>();

            buildingContext.GetOrRegisterSpecificationScope(Arg.Any <Specification <object> >()).Returns(666);

            Action action = () => blockBuilder.Build(buildingContext);

            action.Should().ThrowExactly <InvalidOperationException>().WithMessage("Only properties and variables are valid members to validate, m => m.SomeFunctionReturningReference() looks like it is pointing at something else (a method?).");
        }
예제 #12
0
        public void Should_ThrowException_When_MemberSelectorPointsMoreThanOneLevelDown_ThreeLevels()
        {
            Specification <string> specification = s => s;

            var command         = new MemberCommand <SomeModel, string>(m => m.Member.NestedObject.FullName, specification);
            var blockBuilder    = command.GetScopeBuilder();
            var buildingContext = Substitute.For <IScopeBuilderContext>();

            buildingContext.GetOrRegisterSpecificationScope(Arg.Any <Specification <string> >()).Returns(666);

            Action action = () => blockBuilder.Build(buildingContext);

            action.Should().ThrowExactly <InvalidOperationException>().WithMessage("Only one level of nesting is allowed, m => m.Member.NestedObject.FullName looks like it is going further (member of a member?)");
        }
예제 #13
0
        public ActionResult Edit(int id, MemberCommand model)
        {
            if (ModelState.IsValid)
            {
                Member member = MemberManager.Find(x => x.Id == id);
                Mapper.Map(model, member);

                MemberManager.Update(member);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
예제 #14
0
        public void Should_GetOrRegisterSpecification_And_ModelBlock()
        {
            Specification <object> specification = s => s;

            var command = new MemberCommand <SomeModel, object>(m => m.SomeReferenceProperty, specification);

            var blockBuilder = command.GetScopeBuilder();

            var buildingContext = Substitute.For <IScopeBuilderContext>();

            buildingContext.GetOrRegisterSpecificationScope(Arg.Is <Specification <object> >(arg => ReferenceEquals(arg, specification))).Returns(666);

            var block = blockBuilder.Build(buildingContext);

            buildingContext.Received(1).GetOrRegisterSpecificationScope(Arg.Is <Specification <object> >(arg => ReferenceEquals(arg, specification)));

            block.Should().BeOfType <MemberCommandScope <SomeModel, object> >();

            var modelBlock = (MemberCommandScope <SomeModel, object>)block;

            modelBlock.ScopeId.Should().Be(666);
        }