Пример #1
0
        public ActionResult Edit(int id)
        {
            CodeFormViewModel viewModel = CodeFormViewModel.CreateCodeFormViewModel();

            viewModel.Code   = codeRepository.Get(id);
            viewModel.TaskId = viewModel.Code.Task.Id;
            this.SetBreadcrumbText(viewModel.Code.Name);
            return(View(viewModel));
        }
Пример #2
0
        public ActionResult Create(int taskId)
        {
            CodeFormViewModel viewModel = CodeFormViewModel.CreateCodeFormViewModel();

            viewModel.Code = new Code {
                Name = "НовыйКод", Danger = "1"
            };
            viewModel.TaskId = taskId;
            return(View(viewModel));
        }
Пример #3
0
        public ActionResult Create([CodeBinder(Fetch = false)] Code code)
        {
            if (ViewData.ModelState.IsValid && code.IsValid())
            {
                taskRepository.Get(code.Task.Id).Codes.Add(code);
                codeRepository.SaveOrUpdate(code);
                taskRepository.DbContext.CommitChanges();

                Message = "Код успешно создан.";
                return(this.RedirectToAction <TasksController>(c => c.Edit(code.Task.Id)));
            }

            CodeFormViewModel viewModel = CodeFormViewModel.CreateCodeFormViewModel();

            viewModel.Code = code;
            return(View(viewModel));
        }
Пример #4
0
        public ActionResult Edit([CodeBinder(Fetch = true)] Code code)
        {
            Code codeToUpdate = codeRepository.Get(code.Id);

            TransferFormValuesTo(codeToUpdate, code);

            if (ViewData.ModelState.IsValid && code.IsValid())
            {
                Message = "Код успешно изменен.";
                return(this.RedirectToAction <TasksController>(c => c.Edit(code.Task.Id)));
            }
            else
            {
                codeRepository.DbContext.RollbackTransaction();

                CodeFormViewModel viewModel = CodeFormViewModel.CreateCodeFormViewModel();
                viewModel.Code = code;
                return(View(viewModel));
            }
        }