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)); }
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)); }
// 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)); }
public void Member_Execute_ReturnsEmpty() { var command = new MemberCommand(_console, LoggerMock.GetLogger <MemberCommand>().Object); var resultMessage = command.Execute(); Assert.Equal("", resultMessage); }
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); }
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); }
// 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)); }
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); }
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(); }
public ActionResult Create(MemberCommand model) { if (ModelState.IsValid) { Member member = Mapper.Map <Member>(model); MemberManager.Insert(member); return(RedirectToAction("Index")); } return(View(model)); }
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?)."); }
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?)"); }
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)); }
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); }