private void button3_Click(object sender, EventArgs e) { if (Temped.Count() > 0) { ProjectTaskDto pt = new ProjectTaskDto(); var tempedObject = Temped.Where(s => s.TaskId == long.Parse(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value.ToString())).Select(s => s).FirstOrDefault(); foreach (var a in Temped.ToList()) { if (a == tempedObject) { Temped.Remove(a); } } Entites.Task task = new Entites.Task { Id = tempedObject.TaskId, Name = tempedObject.TaskName }; listTaskComboBox.Add(task); Loaddata(); } else { MessageBox.Show("Không có gì để xóa"); } }
private void button2_Click(object sender, EventArgs e) { try { if (!String.IsNullOrEmpty(listTaskComboBox.Select(s => s.Name).FirstOrDefault())) { var pt = new ProjectTaskDto { ProjectId = AddNewProject.ProjectID, TaskId = listTaskComboBox.Where(s => s.Name == comboBox1.Text).Select(s => s.Id).FirstOrDefault(), TaskName = comboBox1.Text, Billable = comboBox2.Text }; Temped.Add(pt); foreach (var a in listTaskComboBox.ToList()) { if (a.Name == pt.TaskName) { listTaskComboBox.Remove(a); } } dataGridView1.DataSource = Temped; } else { MessageBox.Show("Khong con task de lua chon"); } }catch (Exception ex) { MessageBox.Show($"{ex}"); } }
public async Task <IActionResult> Post([FromBody] ProjectTaskDto dto) { using (Logger.BeginScope("Insert Project Task")) { if (!ModelState.IsValid) { return(BadRequest(new { message = "Not a valid model" + ModelState.ToString() })); } try { _UnitOfWork.Transaction = _UnitOfWork.Begin(); var id = await _UnitOfWork.TaskRepository.InsertProjectTaskAsync(dto); _UnitOfWork.Commit(); return(Ok(id)); } catch (Exception ex) { _UnitOfWork.Dispose(); return(BadRequest(new { message = ex.Message })); } } }
public async Task <ProjectTask> Add(ProjectTaskDto taskDto) { var task = _context.Tasks.Add(_mapper.Map <ProjectTask>(taskDto)); await _context.SaveChangesAsync().ConfigureAwait(false); return(task.Entity); }
public IActionResult Edit(ProjectTaskFilledVm projectTaskFilledVm) { logger.LogDebug($"ProjectTask.Edit [post] is called"); try { if (projectTaskFilledVm == null) { throw new ArgumentException("Variable shuld not be null", nameof(projectTaskFilledVm)); } if (ModelState.IsValid) { ProjectTaskDto projectTaskDto = ConvertToProjectTaskDto.Convert(projectTaskFilledVm.ProjectTasks); ProjectTaskService.Update(projectTaskDto); } else { return(View(projectTaskFilledVm)); } } catch (Exception ex) { logger.LogError(ex.Message); return(View("Error")); } return(RedirectToAction(nameof(Index))); }
public async Task <EntityOperationResult <ProjectTask> > EditItemAsync(ProjectTaskDto projectTaskEditDto) { using (var unitOfWork = _unitOfWorkFactory.MakeUnitOfWork()) { var result = Check(projectTaskEditDto); if (result != null) { return(result); } var projectTask = unitOfWork.ProjectTask.GetById(projectTaskEditDto.Id); try { projectTask.Name = projectTaskEditDto.Name; projectTask.AuthorId = projectTaskEditDto.Author.Id; projectTask.ExecutorId = projectTaskEditDto.Executor.Id; projectTask.Status = (int)projectTaskEditDto.Status; projectTask.ProjectId = projectTaskEditDto.Project.Id; projectTask.Priority = projectTaskEditDto.Priority; projectTask.Comment = projectTaskEditDto.Comment; unitOfWork.ProjectTask.Update(projectTask); await unitOfWork.CompleteAsync(); return(EntityOperationResult <ProjectTask> .Success(projectTask)); } catch (Exception ex) { return(EntityOperationResult <ProjectTask> .Failure().AddError(ex.Message)); } } }
public async Task UpdateOrThrow(ProjectTaskDto taskDto) { await using var transaction = await _context.Database.BeginTransactionAsync().ConfigureAwait(false); var task = await _context.Tasks.FindAsync(taskDto.Id).ConfigureAwait(false) ?? throw new NotFoundException(nameof(ProjectTask), taskDto.Id); if (task.State != taskDto.State) { task.State = taskDto.State; UpdateParentProjectsStates(task); } _mapper.Map(taskDto, task); await _context.SaveChangesAsync().ConfigureAwait(false); await transaction.CommitAsync().ConfigureAwait(false); }
public async Task <EntityOperationResult <ProjectTask> > DeleteItemAsync(ProjectTaskDto projectTDtoDeleteDto) { using (var unitOfWork = _unitOfWorkFactory.MakeUnitOfWork()) { var projectTask = unitOfWork.ProjectTask.GetById(projectTDtoDeleteDto.Id); try { unitOfWork.ProjectTask.Delete(projectTask); await unitOfWork.CompleteAsync(); return(EntityOperationResult <ProjectTask> .Success(projectTask)); } catch (Exception ex) { return(EntityOperationResult <ProjectTask> .Failure().AddError(ex.Message)); } } }
public async Task <EntityOperationResult <ProjectTask> > CreateItemAsync(ProjectTaskDto projectTaskCreateDto) { using (var unitOfWork = _unitOfWorkFactory.MakeUnitOfWork()) { var result = Check(projectTaskCreateDto); if (result != null) { return(result); } if (projectTaskCreateDto.Project == null) { return(EntityOperationResult <ProjectTask> .Failure() .AddError("Не указан Проект")); } try { var project = new ProjectTask { Name = projectTaskCreateDto.Name, AuthorId = projectTaskCreateDto.Author.Id, ExecutorId = projectTaskCreateDto.Executor.Id, Status = (int)projectTaskCreateDto.Status, ProjectId = projectTaskCreateDto.Project.Id, Priority = projectTaskCreateDto.Priority, Comment = projectTaskCreateDto.Comment }; var entity = await unitOfWork.ProjectTask.AddAsync(project); await unitOfWork.CompleteAsync(); return(EntityOperationResult <ProjectTask> .Success(entity)); } catch (Exception ex) { return(EntityOperationResult <ProjectTask> .Failure().AddError(ex.Message)); } } }
private EntityOperationResult <ProjectTask> Check(ProjectTaskDto projectTask) { if (projectTask.Name == string.Empty) { return(EntityOperationResult <ProjectTask> .Failure() .AddError("Не указано наименование")); } if (projectTask.Author == null) { return(EntityOperationResult <ProjectTask> .Failure() .AddError("Не указан Автор")); } if (projectTask.Executor == null) { return(EntityOperationResult <ProjectTask> .Failure() .AddError("Не указан Исполнитель")); } return(null); }
public async Task <int> InsertProjectTaskAsync(ProjectTaskDto dto) { var sql = " DECLARE @ID int;" + " INSERT INTO [dbo].[Task] " + " ([TaskName] " + " ,[StartDate] " + " ,[EndDate]" + " ,[Duration]" + " ,[ProjectId] " + " ,[EmpId] " + " ,[CreatedId] " + " ,[CreatedDate]) " + " VALUES " + " (@TaskName" + " ,@StartDate" + " ,@EndDate" + " ,@Duration" + " ,@ProjectId " + " ,@EmpId" + " ,@CreatedId " + " ,GETDATE() )" + " SET @ID = SCOPE_IDENTITY(); " + " SELECT @ID"; var id = await Connection.QuerySingleAsync <int>(sql, new { TaskName = dto.TaskName, ProjectId = dto.ProjectId, StartDate = dto.StartDate, EndDate = dto.EndDate, Duration = dto.Duration, EmpId = dto.EmpId, CreatedId = dto.CreatedId }, Transaction); return(id); }
public async Task <IActionResult> PostProjectTask(ProjectTaskDto taskDto) { var task = await _taskService.Add(taskDto).ConfigureAwait(false); return(CreatedAtAction(nameof(Get), new { id = task.Id })); }
public async Task <IActionResult> PutProjectTask(int id, ProjectTaskDto taskDto) { await _taskService.UpdateOrThrow(taskDto).ConfigureAwait(false); return(NoContent()); }