コード例 #1
0
        public IActionResult Edit(int taskId, int projectId)
        {
            TasksEditViewModel model = new TasksEditViewModel();

            model.LoadData(_unitOfWork, taskId, projectId);
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(TasksEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var command = new TaskAddOrEditCommand();
                _mapper.Map(model, command);
                var result = await _mediator.SendAsync(command);

                if (result.Success)
                {
                    TempData[NotificationMessageKey] = $"Task {(model.IsAdding ? "created" : "updated")}";
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(string.Empty, result.ErrorMessage);
            }

            return(View(model));
        }
コード例 #3
0
        public IActionResult Edit(TasksEditViewModel model)
        {
            Project project = new Project();

            project             = _unitOfWork.Projects.GetById(model.Tasks.ProjectId);
            model.Tasks.Project = project;

            _unitOfWork.Tasks.Update(model.Tasks);
            _unitOfWork.Save();

            if (model.EmployeeTask.EmployeeId != 0)
            {
                Employee emp = new Employee();
                emp = _unitOfWork.Employees.GetById(model.EmployeeTask.EmployeeId);
                model.EmployeeTask.Employee = emp;
                model.EmployeeTask.Task     = model.Tasks;
                _unitOfWork.EmployeeTasks.Update(model.EmployeeTask);
                _unitOfWork.Save();
            }
            return(RedirectToAction("List", "Tasks"));
        }