public IActionResult Edit(int taskId, int projectId)
        {
            TasksEditViewModel model = new TasksEditViewModel();

            model.LoadData(_unitOfWork, taskId, projectId);
            return(View(model));
        }
Exemple #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));
        }
        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"));
        }