public ActionResult Create(PTaskViewModel pTaskVm) { Project project = this.projectService.Find(ProjectId); if (project == null) { return(HttpNotFound()); } if (project.Owner.Id != User.Identity.GetUserId() && User.IsInRole(RoleConstants.ManagerRole)) { return(new HttpUnauthorizedResult()); } PTask pTask = Mapper.Map <PTask>(pTaskVm); //set users of task ApplicationUser currentUser = this.usersService.Find(User.Identity.GetUserId()); ApplicationUser chosenOwner = this.usersService.Find(pTaskVm.OwnerId); pTask.Author = currentUser; pTask.Owner = chosenOwner; ProjectViewModel updatedProject = Mapper.Map <ProjectViewModel>(this.projectService.AddTask(project, pTask)); if (Request.IsAjaxRequest()) { return(PartialView("_TasksList", updatedProject.Tasks)); } else { return(RedirectToAction("Details", "Project", updatedProject)); } }
public async Task AddTaskCreatedAtRouteStatus() { //Arrange ICollection <PTask> tasks = new List <PTask>() { new PTask { Name = "test" } }; Project project = new Project { Name = "test", ProjectId = 1, PTasks = tasks }; TaskForAdd taskForAdd = new TaskForAdd { Name = "test" }; PTask task = new PTask { Name = "test" }; mockRepoWrapper.Setup(x => x.ProjectRepository.GetProject(1)).Returns(Task.FromResult(project)); mockMapper.Setup(x => x.Map <PTask>(taskForAdd)).Returns(task); mockRepoWrapper.Setup(x => x.SaveAll()).Returns(Task.FromResult(true)); TaskController controller = new TaskController(mockMapper.Object, mockRepoWrapper.Object); //Act var action = await controller.AddTask(1, 1, taskForAdd) as CreatedAtRouteResult; var item = action.Value as TaskForReturn; //Assert Assert.Equal(201, action.StatusCode); Assert.Equal("GetTask", action.RouteName); }
public async Task <Response> Create(PTaskRequest model) { PTask info = _mapper.Map <PTask>(model); info.PTaskStatus = PTaskStatus.New; int result = await _pTaskRepository.Create(info, model.ProjectId); if (result > 0) { return(new Response { IsSuccess = true, Message = Messages.Created.ToString(), Result = result }); } else { return(new Response { IsSuccess = false, Message = Messages.NotCreated.ToString() }); } }
public async Task AddTaskBadRequestStatus() { //Arrange ICollection <PTask> tasks = new List <PTask>() { new PTask { Name = "test" } }; Project project = new Project { Name = "test", ProjectId = 1, PTasks = tasks }; TaskForAdd taskForAdd = new TaskForAdd { Name = "test" }; PTask task = new PTask { Name = "test" }; mockRepoWrapper.Setup(x => x.ProjectRepository.GetProject(1)).Returns(Task.FromResult(project)); mockMapper.Setup(x => x.Map <PTask>(taskForAdd)).Returns(task); mockRepoWrapper.Setup(x => x.SaveAll()).Returns(Task.FromResult(false)); TaskController controller = new TaskController(mockMapper.Object, mockRepoWrapper.Object); //Act var action = await controller.AddTask(1, 1, taskForAdd) as BadRequestObjectResult; //Assert Assert.Equal(400, action.StatusCode); Assert.NotNull(action.Value); }
public async Task <int> Update(PTask data) { _context.PTasks.Update(data); await _context.SaveChangesAsync(); return(1); }
public async Task ChangeTaskOwnerCreatedAtRouteStatus() { //Arrange PTask task = new PTask { Name = "test" }; User user = new User { Nickname = "test", Id = 2 }; TaskForReturnChangePhotoInfo taskForReturn = new TaskForReturnChangePhotoInfo { TaskOwner = 2 }; mockRepoWrapper.Setup(x => x.TaskRepository.GetTask(1)).Returns(Task.FromResult(task)); mockRepoWrapper.Setup(x => x.UserRepository.GetUserByNick("test")).Returns(Task.FromResult(user)); mockRepoWrapper.Setup(x => x.SaveAll()).Returns(Task.FromResult(true)); mockMapper.Setup(x => x.Map <TaskForReturnChangePhotoInfo>(task)).Returns(taskForReturn); TaskController controller = new TaskController(mockMapper.Object, mockRepoWrapper.Object); //Act var action = await controller.ChangeTaskOwner(1, 1, "test") as CreatedAtRouteResult; //Assert Assert.Equal(201, action.StatusCode); Assert.Equal("GetTask", action.RouteName); }
public ActionResult Report(PTaskViewModel pTaskVm, int?taskNumber) { if (taskNumber != null) { ViewData["counter"] = taskNumber; } if (ModelState.IsValid) { PTask pTask = this.ptaskService.Find(pTaskVm.Id); pTask.ProgressPercent = pTaskVm.ProgressPercent; TimeReportItem report = new TimeReportItem() { HoursSpend = pTaskVm.HoursSpend }; this.ptaskService.AddReport(pTask, report); PTaskViewModel updatedTaskVm = Mapper.Map <PTaskViewModel>(ptaskService.Find(pTaskVm.Id)); if (Request.IsAjaxRequest()) { Response.StatusCode = (int)HttpStatusCode.OK; return(PartialView("_Task", updatedTaskVm)); } } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_ReportTime", pTaskVm)); }
public async Task ChangeTaskOwnerBadRequestStatus() { //Arrange PTask task = new PTask { Name = "test" }; User user = new User { Nickname = "test", Id = 2 }; TaskForReturnChangePhotoInfo taskForReturn = new TaskForReturnChangePhotoInfo { TaskOwner = 2 }; mockRepoWrapper.Setup(x => x.TaskRepository.GetTask(1)).Returns(Task.FromResult(task)); mockRepoWrapper.Setup(x => x.UserRepository.GetUserByNick("test")).Returns(Task.FromResult(user)); mockRepoWrapper.Setup(x => x.SaveAll()).Returns(Task.FromResult(false)); TaskController controller = new TaskController(mockMapper.Object, mockRepoWrapper.Object); //Act var action = await controller.ChangeTaskOwner(1, 1, "test") as BadRequestObjectResult; //Assert Assert.Equal(400, action.StatusCode); Assert.NotNull(action.Value); }
public Project AddTask(Project project, PTask task) { task.CreatedOn = DateTime.Now; project.Tasks.Add(task); base.Update(project); base.SaveChanges(); return(project); }
protected override void UnloadData() { try { if (SuppressWc) { return; } if (!PTask.IsComplete) { PTask.Wait(); } if (!CTask.IsComplete) { CTask.Wait(); } if (!ITask.IsComplete) { ITask.Wait(); } if (IsServer || DedicatedServer) { MyAPIGateway.Multiplayer.UnregisterMessageHandler(ServerPacketId, ProccessServerPacket); } else { MyAPIGateway.Multiplayer.UnregisterMessageHandler(ClientPacketId, ClientReceivedPacket); MyAPIGateway.Multiplayer.UnregisterMessageHandler(StringPacketId, StringReceived); } if (HandlesInput) { MyAPIGateway.Utilities.MessageEntered -= ChatMessageSet; } MyAPIGateway.Utilities.UnregisterMessageHandler(7771, Handler); MyAPIGateway.TerminalControls.CustomControlGetter -= CustomControlHandler; MyEntities.OnEntityCreate -= OnEntityCreate; MyAPIGateway.Gui.GuiControlCreated -= MenuOpened; MyAPIGateway.Gui.GuiControlRemoved -= MenuClosed; MyVisualScriptLogicProvider.PlayerDisconnected -= PlayerDisconnected; MyVisualScriptLogicProvider.PlayerRespawnRequest -= PlayerConnected; ApiServer.Unload(); PurgeAll(); Log.Line("Logging stopped."); Log.Close(); } catch (Exception ex) { Log.Line($"Exception in UnloadData: {ex}"); } }
public async Task <int> Create(PTask data, int ProjectId) { data.Project = await _context.Projects.FindAsync(ProjectId); _context.PTasks.Add(data); await _context.SaveChangesAsync(); return(data.Id); }
private ObjPTask Map(PTask pTask) { return(new ObjPTask() { Id = pTask.Id, Name = pTask.Name, Description = pTask.Description, Position = pTask.Position }); }
public async Task <PTask> FindById(int id) { PTask data = await _context.PTasks .Include(o => o.Comments) .ThenInclude(k => k.Attachments) .Where(k => k.Id == id) .FirstOrDefaultAsync(); return(data); }
public ActionResult Delete(int?Id) { if (Id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PTask task = ptaskService.Find(Id); return(View("Details", task)); }
public float GetTaskTimeSpend(PTask task) { float time = 0; if (task.TimeReportList.Any()) { foreach (var report in task.TimeReportList) { time += report.HoursSpend; } } return(time); }
private async void AddNewTaskAction() { try { await Logger.LogMessage("Dodawanie nowego zadania"); string TaskTitle = await ShowInputContentDialog("Wprowadź nazwę zadania", "Dodaj zadanie", "Dodaj", "Anuluj", string.Empty); if (string.IsNullOrEmpty(TaskTitle)) { LocalNotification localNotification = new LocalNotification { Content = "Wprowadzono błędną nazwę zadania", Duration = 2500 }; Messenger.Default.Send(new NotificationMessage <LocalNotification>(localNotification, "NewLocalNotification")); await Logger.LogMessage("Wprowadzono błędną nazwę zadania", 3); return; } if (TaskTitle == "-1") { return; } PTask newTask = new PTask() { Title = TaskTitle, CreatedOn = DateTime.Now, Seconds = 0, ProjectId = SelectedProject.ProjectId }; await App.Database.AddNewTask(newTask); Tasks.Add(newTask); Projects.Where(x => x.ProjectId == SelectedProject.ProjectId).FirstOrDefault().GetTasks(); RenumberTasks(); await Logger.LogMessage("Pomyślnie dodano nowe zadanie", 3); } catch (Exception ex) { await Logger.LogMessage(ex.ToString(), 3); ShowConfirmContentDialog("Błąd", "Potwierdź", "Wystąpił błąd! Sprawdź logi programu."); } }
public async Task <int> Delete(int id) { PTask data = await _context.PTasks.FindAsync(id); if (data == null) { return(0); } if (data.Comments != null) { return(0); } _context.PTasks.Remove(data); await _context.SaveChangesAsync(); return(1); }
public async Task ChangeStatusPriorityBadRequestStatus() { //Arrange PTask task = new PTask { Name = "test" }; mockRepoWrapper.Setup(x => x.TaskRepository.GetTask(1)).Returns(Task.FromResult(task)); mockRepoWrapper.Setup(x => x.SaveAll()).Returns(Task.FromResult(false)); TaskController controller = new TaskController(mockMapper.Object, mockRepoWrapper.Object); //Act var action = await controller.ChangeStatusPriority(1, "status", "high") as BadRequestObjectResult; //Assert Assert.Equal(400, action.StatusCode); Assert.NotNull(action.Value); }
private async void EditTaskAction() { try { await Logger.LogMessage("Rozpoczęcie edycji zadania"); string TaskTitle = await ShowInputContentDialog("Wprowadź nazwę zadania", "Edycja zadania", "Zapisz", "Anuluj", SelectedTask.Title); if (string.IsNullOrEmpty(TaskTitle)) { LocalNotification localNotification = new LocalNotification { Content = "Wprowadzono błędną nazwę zadania", Duration = 2500 }; Messenger.Default.Send(new NotificationMessage <LocalNotification>(localNotification, "NewLocalNotification")); await Logger.LogMessage("Wprowadzono błędną nazwę zadania", 3); return; } if (TaskTitle == "-1") { return; } PTask editedTask = SelectedTask; editedTask.Title = TaskTitle; editedTask.ModifiedOn = DateTime.Now; await App.Database.UpdateTask(editedTask); Tasks.Where(x => x.TaskId == SelectedTask.TaskId).FirstOrDefault().Title = TaskTitle; Tasks.Where(x => x.TaskId == SelectedTask.TaskId).FirstOrDefault().ModifiedOn = editedTask.ModifiedOn; await Logger.LogMessage("Edycja zadania zakończona powodzeniem", 0); } catch (Exception ex) { await Logger.LogMessage(ex.ToString(), 3); ShowConfirmContentDialog("Błąd", "Potwierdź", "Wystąpił błąd! Sprawdź logi programu."); } }
public async Task DeleteTaskOkStatus() { //Arrange PTask task = new PTask { Name = "test" }; mockRepoWrapper.Setup(x => x.TaskRepository.GetTask(1)).Returns(Task.FromResult(task)); mockRepoWrapper.Setup(x => x.TaskRepository.Delete(task)).Verifiable(); mockRepoWrapper.Setup(x => x.SaveAll()).Returns(Task.FromResult(true)); TaskController controller = new TaskController(mockMapper.Object, mockRepoWrapper.Object); //Act var action = await controller.DeleteTask(1) as OkResult; //Assert Assert.Equal(200, action.StatusCode); mockRepoWrapper.Verify(x => x.TaskRepository.Delete(task), Times.Once); }
public ActionResult DeleteTask(int?Id) { if (Id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PTask task = ptaskService.Find(Id); if (task == null) { return(HttpNotFound()); } ptaskService.Delete(task.Id); ProjectViewModel projectVm = Mapper.Map <ProjectViewModel>(this.projectService.Find(ProjectId)); return(PartialView("_TasksList", projectVm.Tasks)); }
public async Task <Response> FindById(int id) { PTask result = await _pTaskRepository.FindById(id); if (result != null) { return(new Response { IsSuccess = true, Message = Messages.Found.ToString(), Result = result }); } else { return(new Response { IsSuccess = false, Message = Messages.NotFound.ToString() }); } }
public async Task <Response> Update(int id, PTaskRequest request) { PTask pTask = await _pTaskRepository.FindById(id); if (pTask == null) { return(new Response { IsSuccess = false, Message = Messages.NotFound.ToString() }); } pTask.Title = request.Title; pTask.Description = request.Description; pTask.EndDate = request.EndDate; pTask.PTaskStatus = request.PTaskStatus; int result = await _pTaskRepository.Update(pTask); if (result > 0) { return(new Response { IsSuccess = true, Message = Messages.Updated.ToString(), Result = result }); } else { return(new Response { IsSuccess = false, Message = Messages.NotUpdated.ToString() }); } }
public async Task GetTaskOkStatus() { //Arrange PTask task = new PTask { Name = "test", PTaskId = 1 }; TaskForReturn taskForReturn = new TaskForReturn { Name = "test", TaskId = 1 }; mockRepoWrapper.Setup(x => x.TaskRepository.GetTask(1)).Returns(Task.FromResult(task)); mockMapper.Setup(x => x.Map <TaskForReturn>(task)).Returns(taskForReturn); TaskController controller = new TaskController(mockMapper.Object, mockRepoWrapper.Object); //Act var action = await controller.GetTask(1) as OkObjectResult; var item = action.Value as TaskForReturn; //Assert Assert.Equal(200, action.StatusCode); Assert.Equal(1, item.TaskId); }
public ActionResult Update(PTaskViewModel pTaskVm, int?taskNumber) { if (taskNumber != null) { ViewData["counter"] = taskNumber; } if (ModelState.IsValid) { PTask pTask = Mapper.Map <PTask>(pTaskVm); this.ptaskService.Update(pTask); PTaskViewModel updatedTaskVm = Mapper.Map <PTaskViewModel>(ptaskService.Find(pTaskVm.Id)); Response.StatusCode = (int)HttpStatusCode.OK; return(PartialView("_Task", updatedTaskVm)); } Response.StatusCode = (int)HttpStatusCode.BadRequest; ViewData["Users"] = new SelectList(this.usersService.GetAll().Where(u => u.UserName != PtConstants.AdminUsername).ToList(), "Id", "UserName", pTaskVm.OwnerId); return(PartialView("_UpdateTask", pTaskVm)); }
public async Task Update(int id, PTask task) { unitOfWork.ProjectTaskRepository.Update(id, task); await unitOfWork.CommitChanges(); }
public async Task Create(PTask task) { unitOfWork.ProjectTaskRepository.Create(task); await unitOfWork.CommitChanges(); }