public async Task <IActionResult> AddFeature(FeatureViewModel model) { if (ModelState.IsValid) { var afc = new AddFeatureCommand() { Feature = new Feature() { Title = model.Title, Description = model.Description } }; var result = await _cp.ProcessAsync(afc); if (result.Succeeded) { return(RedirectToAction("ManageFeatures")); } else { // To do, better exeception handling return(NotFound()); } } return(View(model)); }
public void Execute_Should_Not_Add_Invalid_Feature() { AddFeatureCommandHandler sut = GetCommandHandler(); AddFeatureCommand command = FeatureCommandHandlerTestHelper.GetAddCommand("Feature 1", "a".PadLeft(101, 'a')); string expectedInvalid = string.Format(MessagesModel.MaxLength, "100"); FeatureCommandResult result = sut.Execute(command); var calls = sut.WriteRepository.ReceivedCalls().Count(); Assert.AreEqual(0, calls); }
public FeatureVm AddFeature(FeatureVm vm) { if (vm == null) { throw new ArgumentNullException(string.Format(MessagesModel.NullValueError, "vm")); } AddFeatureCommand command = new AddFeatureCommand(vm.Id, vm.DateAdded, vm.Name, vm.UserId, vm.Ticket, vm.IsActive, vm.IsEnabled, vm.StrategyId); FeatureCommandResult result = this.commandDispatcher.Dispatch <AddFeatureCommand, FeatureCommandResult, Feature>(command); vm = FeatureModelHelper.CommandResultToFeatureVm(result); return(vm); }
public static AddFeatureCommand GetAddCommand(string name = null, string ticket = null, string id = null) { string defaultId = "id1"; string defaultName = "Feature 1"; string defaultTicket = "ticket1"; DateTime date = DateTime.Now; string user = "******"; id = id ?? defaultId; name = name ?? defaultName; ticket = ticket ?? defaultTicket; AddFeatureCommand command = new AddFeatureCommand(id, date, name, user, ticket); return(command); }
public FeatureCommandResult Execute(AddFeatureCommand command) { FeatureCommandResult result = FeatureCommandHandlerHelper.Validate(command, this.WriteRepository, this.ReadRepository); // TODO: Research how to handle concurrency in MongoDb. // I am still a MongoDb newbie so there is probably a better way to handle concurrency issues. // For now, if a duplicate is found we will throw an exception. if (FeatureCommandHandlerHelper.IsDuplicateName(command.Name, this.ReadRepository)) { result.Valid = false; result.InvalidName = string.Format("A feature already exists with the name {0}", command.Name); } if (!result.Valid) { return(result); } Feature feature = new Feature(command.Id, command.DateAdded, command.Name, command.UserId, command.Ticket, command.IsActive, command.IsEnabled, command.StrategyId); this.WriteRepository.Insert(feature); return(result); }