Exemplo n.º 1
0
 public ActionResult EditNewNameChange(OperationNameChangeViewModel vm)
 {
     if (ModelState.IsValid)
     {
         this.SaveOperationNameChangeViewModel(vm);
         return(RedirectToAction("Details", new { id = vm.CurrentOperationId }));
     }
     return(EditNewNameChange(vm.CurrentOperationId));
 }
Exemplo n.º 2
0
        public ActionResult EditNewNameChange(int id)
        {
            Operation op = this.orgTasks.GetOperation(id);

            if (op != null)
            {
                ViewBag.CurrentOperation = op;
                OperationNameChangeViewModel vm = new OperationNameChangeViewModel();
                vm.CurrentOperationId = op.Id;
                vm.OldOperationId     = op.Id;
                vm.NewOperationId     = op.NextOperation.Id;
                return(View(vm));
            }
            return(new HttpNotFoundResult());
        }
Exemplo n.º 3
0
        protected void SaveOperationNameChangeViewModel(OperationNameChangeViewModel vm)
        {
            Operation oldOp = vm.OldOperationId.HasValue ? this.orgTasks.GetOperation(vm.OldOperationId.Value) : null;
            Operation newOp = vm.NewOperationId.HasValue ? this.orgTasks.GetOperation(vm.NewOperationId.Value) : null;

            if (oldOp != null)
            {
                oldOp.NextOperation = newOp;
                oldOp = this.orgTasks.SaveOperation(oldOp);
            }

            if (newOp != null)
            {
                newOp.FormerOperations.Clear();
                newOp = this.orgTasks.SaveOperation(newOp);
            }
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value != null)
            {
                OperationNameChangeViewModel vm = (OperationNameChangeViewModel)value;

                // one of the operations must be the current one
                if (vm.CurrentOperationId != vm.OldOperationId && vm.CurrentOperationId != vm.NewOperationId)
                {
                    return(new ValidationResult("Either the former or new operation must be the current one."));
                }

                // operations must not be the same
                if (vm.OldOperationId.HasValue && vm.OldOperationId == vm.NewOperationId)
                {
                    return(new ValidationResult("Former and new operations can not be the same."));
                }
            }
            return(ValidationResult.Success);
        }