WorkTaskDTO IWorkTasksService.UpdateWorkTask(WorkTaskDTO newTask) { var updatedTask = _unitOfWork.WorkTasks.Update(_mapper.Map <WorkTask>(newTask)); _unitOfWork.Save(); return(_mapper.Map <WorkTaskDTO>(updatedTask)); }
WorkTaskDTO IWorkTasksService.AddWorkTask(WorkTaskDTO newTask, string performerId) { IEnumerable <Position> performerPosition = _unitOfWork.Positions.Filter(p => p.IdProject == newTask.IdProject && p.IdUser == performerId); Position assignPosition; if (performerPosition.Count() == 0) { assignPosition = _unitOfWork.Positions.Create(new Position { IdProject = newTask.IdProject, IdUser = performerId, Name = "performer" }); _unitOfWork.Save(); } else { assignPosition = performerPosition.First(); } newTask.StartDate = DateTime.Now; newTask.IdPerformer = assignPosition.Id; var addedTask = _unitOfWork.WorkTasks.Create(_mapper.Map <WorkTask>(newTask)); _unitOfWork.Save(); return(_mapper.Map <WorkTaskDTO>(addedTask)); }
public async Task <ActionResult <WorkTask> > PostWorkTask(WorkTaskDTO workTaskDto) { var wTask = _context.WorkTasks.Where(c => c.TaskName == workTaskDto.TaskName).FirstOrDefault(); if (wTask != null) { return(Conflict(new RespStatus { Status = "Failure", Message = "TaskName Already Exists" })); } WorkTask workTask = new WorkTask { SubProjectId = workTaskDto.SubProjectId, TaskName = workTaskDto.TaskName, TaskDesc = workTaskDto.TaskDesc }; _context.WorkTasks.Add(workTask); await _context.SaveChangesAsync(); return(Ok(new RespStatus { Status = "Success", Message = "Work-Task Created!" })); }
public ActionResult Edit(WorkTaskViewModel model) { WorkTaskDTO workTask = workTaskService.GetWorkTask(model.Id); if (workTask == null) { return(NotFound()); } if (ModelState.IsValid) { workTask.Title = model.Title; workTask.Description = model.Description; workTask.CreatedDate = model.CreatedDate; workTask.AuthorUserId = model.AuthorUserId; workTask.TaskState = model.TaskState; workTask.UpdatedDate = DateTime.Now; workTask.LastModifiedUserId = model.LastModifiedUserId; workTaskService.UpdateWorkTask(workTask); return(RedirectToAction("index")); } else { return(View(model)); } }
public async Task <IActionResult> PutWorkTask(int id, WorkTaskDTO workTaskDto) { if (id != workTaskDto.Id) { return(BadRequest()); } var workTask = await _context.WorkTasks.FindAsync(id); workTask.Id = workTaskDto.Id; workTask.SubProjectId = workTaskDto.SubProjectId; workTask.TaskName = workTaskDto.TaskName; workTask.TaskDesc = workTaskDto.TaskDesc; _context.WorkTasks.Update(workTask); //_context.Entry(workTaskDto).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkTaskExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutWorkTask(int id, WorkTaskDTO workTaskDto) { if (id != workTaskDto.Id) { return(Conflict(new RespStatus { Status = "Failure", Message = "Id is invalid" })); } var workTask = await _context.WorkTasks.FindAsync(id); workTask.TaskName = workTaskDto.TaskName; workTask.TaskDesc = workTaskDto.TaskDesc; _context.WorkTasks.Update(workTask); //_context.Entry(workTaskDto).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(Ok(new RespStatus { Status = "Success", Message = "Work Task Details Updated!" })); }
public IHttpActionResult GetWorkTask(int id) { WorkTaskDTO workTask = _service.GetWorkTaskById(id); if (workTask == null) { return(NotFound()); } return(Ok(workTask)); }
public async Task <ActionResult <WorkTask> > PostWorkTask(WorkTaskDTO workTaskDto) { WorkTask workTask = new WorkTask(); workTask.SubProjectId = workTaskDto.SubProjectId; workTask.TaskName = workTaskDto.TaskName; workTask.TaskDesc = workTaskDto.TaskDesc; _context.WorkTasks.Add(workTask); await _context.SaveChangesAsync(); return(CreatedAtAction("GetWorkTask", new { id = workTask.Id }, workTask)); }
public void UpdateWorkTask(WorkTaskDTO workTaskDto) { var WorkTask = Database.WorkTaskManager.Get(workTaskDto.Id); WorkTask.Title = workTaskDto.Title; WorkTask.Description = workTaskDto.Description; WorkTask.CreatedDate = workTaskDto.CreatedDate; WorkTask.UpdatedDate = workTaskDto.UpdatedDate; WorkTask.AuthorUserId = workTaskDto.AuthorUserId; WorkTask.LastModifiedUserId = Database.UserProfileManager.GetUserByEmail(workTaskDto.LastModifiedUserId).Id; WorkTask.TaskStateId = Database.TaskStateManager.Get(workTaskDto.TaskState).TaskStateId; Database.WorkTaskManager.Update(WorkTask); Database.SaveAsync(); }
public IHttpActionResult PostWorkTask([FromUri] string id, [FromBody] WorkTaskDTO workTask) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (WorkTaskExists(workTask.Id)) { return(BadRequest("Order exists")); } return(CreatedAtRoute("GetWorkTask", new { id = workTask.Id }, _service.AddWorkTask(workTask, id))); }
public IHttpActionResult PutWorkTask(WorkTaskDTO workTask) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!WorkTaskExists(workTask.Id)) { return(NotFound()); } return(Ok(_service.UpdateWorkTask(workTask))); }
public void InsertWorkTask(WorkTaskDTO workTaskDto) { var WorkTask = new WorkTask { Title = workTaskDto.Title, Description = workTaskDto.Description, CreatedDate = workTaskDto.CreatedDate, UpdatedDate = workTaskDto.UpdatedDate, AuthorUserId = Database.UserProfileManager.GetUserByEmail(workTaskDto.AuthorUserId).Id, LastModifiedUserId = Database.UserProfileManager.GetUserByEmail(workTaskDto.AuthorUserId).Id, TaskStateId = Database.TaskStateManager.Get(workTaskDto.TaskState).TaskStateId }; Database.WorkTaskManager.Insert(WorkTask); Database.SaveAsync(); }
public async Task <ActionResult <WorkTaskDTO> > GetWorkTask(int id) { WorkTaskDTO workTaskDto = new WorkTaskDTO(); var worktask = await _context.WorkTasks.FindAsync(id); if (worktask == null) { return(NotFound()); } workTaskDto.Id = worktask.Id; workTaskDto.SubProjectId = worktask.SubProjectId; workTaskDto.TaskName = worktask.TaskName; workTaskDto.TaskDesc = worktask.TaskDesc; return(workTaskDto); }
public ActionResult Delete(int id) { WorkTaskDTO workTask = workTaskService.GetWorkTask(id); if (workTask == null) { return(NotFound()); } WorkTaskViewModel model; model = new WorkTaskViewModel() { Title = workTask.Title, Description = workTask.Description, CreatedDate = workTask.CreatedDate, }; return(View(model)); }
public async Task <ActionResult <IEnumerable <WorkTaskDTO> > > GetWorkTasks() { List <WorkTaskDTO> ListWorkTaskDto = new List <WorkTaskDTO>(); var WorkTasks = await _context.WorkTasks.ToListAsync(); foreach (WorkTask worktask in WorkTasks) { WorkTaskDTO workTaskDto = new WorkTaskDTO(); workTaskDto.Id = worktask.Id; workTaskDto.SubProjectId = worktask.SubProjectId; workTaskDto.TaskName = worktask.TaskName; workTaskDto.TaskDesc = worktask.TaskDesc; ListWorkTaskDto.Add(workTaskDto); } return(ListWorkTaskDto); }
public ActionResult Edit(int id) { WorkTaskDTO workTask = workTaskService.GetWorkTask(id); if (workTask == null) { return(NotFound()); } WorkTaskViewModel model; model = new WorkTaskViewModel() { Title = workTask.Title, Description = workTask.Description, CreatedDate = workTask.CreatedDate, AuthorUserId = workTask.AuthorUserId, TaskState = workTask.TaskState }; return(View(model)); }
public ActionResult Create(WorkTaskViewModel workTask) { if (workTask.Title != null && workTask.Description != null) { var WorkTaskDto = new WorkTaskDTO { Title = workTask.Title, Description = workTask.Description, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now, AuthorUserId = workTask.AuthorUserId, LastModifiedUserId = workTask.AuthorUserId, TaskState = "ToDo" }; workTaskService.InsertWorkTask(WorkTaskDto); return(RedirectToAction("Index")); } return(View()); }
public async Task <ActionResult <WorkTaskDTO> > GetWorkTask(int id) { var worktask = await _context.WorkTasks.FindAsync(id); if (worktask == null) { return(Ok(new RespStatus { Status = "Failure", Message = "Work Task Id is invalid!" })); } WorkTaskDTO workTaskDto = new WorkTaskDTO { Id = worktask.Id, SubProjectId = worktask.SubProjectId, SubProject = _context.SubProjects.Find(worktask.SubProjectId).SubProjectName, TaskName = worktask.TaskName, TaskDesc = worktask.TaskDesc }; return(workTaskDto); }