Exemplo n.º 1
0
        public async Task <IActionResult> EditFeature(FeatureViewModel model)
        {
            if (ModelState.IsValid)
            {
                var efc = new EditFeatureCommand()
                {
                    Id             = model.Id,
                    NewTitle       = model.Title,
                    NewDescription = model.Description
                };

                var result = await _cp.ProcessAsync(efc);

                if (result.Succeeded)
                {
                    return(RedirectToAction("ManageFeatures"));
                }
                else
                {
                    // To Do - Better Error handling
                    return(NotFound());
                }
            }
            return(View(model));
        }
Exemplo n.º 2
0
            public void Execute_Should_Not_Edit_Invalid_Feature()
            {
                EditFeatureCommandHandler sut = GetCommandHandler();

                EditFeatureCommand command = FeatureCommandHandlerTestHelper.GetEditCommand("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);
            }
Exemplo n.º 3
0
        //TODO: Decide what happens if we happen to have a duplicate key here.
        public FeatureVm EditFeature(FeatureVm vm)
        {
            if (vm == null)
            {
                throw new ArgumentNullException(string.Format(MessagesModel.NullValueError, "vm"));
            }

            EditFeatureCommand command = new EditFeatureCommand(vm.Id, vm.DateAdded, vm.Name, vm.UserId, vm.Ticket, vm.IsActive, vm.IsEnabled, vm.StrategyId);

            FeatureCommandResult result = this.commandDispatcher.Dispatch <EditFeatureCommand, FeatureCommandResult, Feature>(command);

            vm = FeatureModelHelper.CommandResultToFeatureVm(result);

            return(vm);
        }
        public FeatureCommandResult Execute(EditFeatureCommand command)
        {
            FeatureCommandResult result = FeatureCommandHandlerHelper.Validate(command, this.WriteRepository, this.ReadRepository);

            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.Update(feature);

            return(result);
        }
        public static EditFeatureCommand GetEditCommand(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;

            EditFeatureCommand command = new EditFeatureCommand(id, date, name, user, ticket);

            return(command);
        }