Exemplo n.º 1
0
        public AddEditViewModel AddEdit(AddEditInputViewModel inputViewModel)
        {
            AddEditViewModel model = null;
            // we came here from an error, use the current state
            if (!string.IsNullOrEmpty(inputViewModel.ErrorMessage))
            {
                model = new AddEditViewModel()
                {
                    AssignedTo = inputViewModel.AssignedTo,
                    Description = inputViewModel.Description,
                    Id = inputViewModel.Id,
                    CompletedOn = inputViewModel.CompletedDate,
                    ErrorMessage = inputViewModel.ErrorMessage
                };
            }
            else
            {
                if (inputViewModel.Id != 0)
                {
                    var task = _fubuTodoService.LoadTask(inputViewModel.Id);
                    if (task != null)
                    {
                        model = new AddEditViewModel
                        {
                            AssignedTo = task.AssignedTo,
                            CompletedOn = task.CompletedOn,
                            Description = task.Description,
                            Id = task.Id,
                            IsCompleted = task.IsCompleted,
                        };
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
              {
                    model = new AddEditViewModel();
                }
            }

            return model;
        }
Exemplo n.º 2
0
        public FubuContinuation AddUpdate(AddEditViewModel model)
        {
            string errorMessage;
            if (!ValidateData(model, out errorMessage))
            {
                AddEditInputViewModel inputModel = new AddEditInputViewModel
                {
                    AssignedTo = model.AssignedTo,
                    Description = model.Description,
                    Id = model.Id.HasValue ? model.Id.Value : 0,
                    ErrorMessage = errorMessage,
                    IsCompleted = model.IsCompleted,
                };
                return FubuContinuation.TransferTo(inputModel, "get");
            }
            int id = model.Id.HasValue ? model.Id.Value : 0;

            FubuTask task = new FubuTask
            {
                Description = model.Description,
                AssignedTo = model.AssignedTo,

            };
            if (id > 0)
            {
                task.Id = id;
            }
            if (!model.CompletedOn.HasValue && model.IsCompleted)
            {
                task.CompletedOn = DateTime.Now;
            }

            _fubuTodoService.SaveTask(task);

            return FubuContinuation.RedirectTo<IndexInputModel>();
        }