public void TasksRepository_Update_when_task_is_not_found() { var task = _repository.Update(new Task { Id = Guid.NewGuid(), Title = "New Task" }); var taskUpdated = _repository.GetById(task.Id); Assert.AreEqual(task.Id, taskUpdated.Id); _repository.Delete(taskUpdated.Id); }
public ActionResult EditTask(int?id) { if (AuthenticationManager.LoggedUser == null) { return(RedirectToAction("Login", "Home")); } TasksRepository tasksRepository = new TasksRepository(new TaskManagerDb()); UsersRepository usersRepository = new UsersRepository(new TaskManagerDb()); Task task = null; if (id == null) { task = new Task(); task.CreatorId = AuthenticationManager.LoggedUser.Id; task.DateCreated = DateTime.Now; task.LastModified = DateTime.Now; task.IsDone = false; } else { task = tasksRepository.GetById(id.Value); } ViewData["task"] = task; ViewData["users"] = usersRepository.GetAll(); return(View()); }
private void MakeComment() { Console.Clear(); Comentary comentary = new Comentary(); comentary.UserId = AuthenticationService.LoggedUser.Id; Console.WriteLine("Add new Comment on Task:"); Console.Write("Task ID: "); comentary.TaskId = Convert.ToInt32(Console.ReadLine()); TasksRepository tasksRepository = new TasksRepository("tasks.txt"); TaskData taskData = tasksRepository.GetById(comentary.TaskId); if (taskData.Creator == AuthenticationService.LoggedUser.Id || taskData.ResponsibleUser == AuthenticationService.LoggedUser.Id) { Console.Write("Commentary: "); comentary.ComentaryText = Console.ReadLine(); ComentaryRepository comentaryRepository = new ComentaryRepository("comentaries.txt"); comentaryRepository.Insert(comentary); Console.WriteLine("Comentary made successfully."); } else { Console.WriteLine("You can comment only task you created or you are responsible for."); } Console.ReadKey(true); }
public void TodoController_Put() { _taskOne.Title = "Name Updated"; var jsonTask = JsonHelper.JsonSerialize <Task>(_taskOne); var content = new System.Net.Http.StringContent(jsonTask, Encoding.UTF8, "application/json"); var response = _server.HttpClient.PutAsync("/todo", content).Result; var result = response.Content.ReadAsStringAsync().Result; var taskUpdated = JsonHelper.JsonDeserialize <TaskModel>(result); var taskFound = _repository.GetById(_taskOne.Id); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(taskUpdated.id, taskFound.Id); Assert.AreEqual(taskUpdated.title, taskFound.Title); _repository.Delete(taskFound.Id); }
internal void Delete(int id) { var data = _repo.GetById(id); if (data == null) { throw new Exception("Invalid Id"); } _repo.Delete(id); }
public void SetUserForTask(int id) { string email = Context.User.Identity.Name; var user = userRepo.GetByEmail(email); taskRepo.SetUserForTask(id, user.Id); Task task = taskRepo.GetById(id); Clients.All.userWasSet(new { UserName = task.User.Name, Id = task.Id, UserId = task.UserId }); }
public Task GetById(int taskId) { Task exists = _repo.GetById(taskId); if (exists == null) { throw new Exception("Invalid Task Id"); } return(exists); }
internal Tasky GetById(int id) { var data = _repo.GetById(id); if (data == null) { throw new Exception("Invalid Id"); } return(data); }
public ActionResult Details(int id) { //all object that we want to map with tryupdatemodel TaskDetailsVM model = new TaskDetailsVM(); model.PagerComments = new Pager(); model.PagerWorkLog = new Pager(); TryUpdateModel(model); //All repositories TasksRepository taskRepo = new TasksRepository(); UsersRepository userRepo = new UsersRepository(); TimeRepository timeRepo = new TimeRepository(); CommentsRepository commentRepo = new CommentsRepository(); //get the specific name that we show (inache kazano da ne e int kakto vika Bai Georgi) TaskEntity task = (id <= 0) ? new TaskEntity() : taskRepo.GetById(id); UserEntity creatorUser = null; UserEntity responsibleUser = null; if (id == 0) { creatorUser = userRepo.GetById(AuthenticationManager.LoggedUser.Id); responsibleUser = userRepo.GetById(AuthenticationManager.LoggedUser.Id); } else { creatorUser = userRepo.GetById(task.CreatorId); responsibleUser = userRepo.GetById(task.ResponsibleUsers); } //fill the model model.Id = task.Id; model.CreatorName = creatorUser.FirstName + " " + creatorUser.LastName; model.ResponsibleName = responsibleUser.FirstName + " " + responsibleUser.LastName; model.Content = task.Content; model.Title = task.Title; model.CreateTime = task.CreateTime; UserEntity Users = userRepo.GetAll().FirstOrDefault(u => u.Id == task.CreatorId); //fill the model's list that give to the partialsViews model.CommentsList = commentRepo.GetAll(c => c.TaskId == model.Id, model.PagerComments.CurrentPage, model.PagerComments.PageSize).ToList(); model.WorkLogList = timeRepo.GetAll(w => w.TaskId == model.Id, model.PagerWorkLog.CurrentPage, model.PagerWorkLog.PageSize).ToList(); //fill the pager with the specific data //Yanka beshe tuk :D :D :D kaza da go iztriq ama nqma da e string action = this.ControllerContext.RouteData.Values["action"].ToString(); string controller = this.ControllerContext.RouteData.Values["controller"].ToString(); model.PagerComments = new Pager(commentRepo.GetAll().Count(c => c.TaskId == model.Id), model.PagerComments.CurrentPage, "PagerComments.", action, controller, model.PagerComments.PageSize); model.PagerWorkLog = new Pager(timeRepo.GetAll().Count(l => l.TaskId == model.Id), model.PagerWorkLog.CurrentPage, "PagerWorkLog.", action, controller, model.PagerWorkLog.PageSize); return(View(model)); }
public ActionResult PatchTask(string id, [FromBody] JsonPatchDocument <Task> patchEntity) { var entity = tasksRepository.GetById(id); if (entity == null) { return(NotFound()); } patchEntity.ApplyTo(entity, ModelState); tasksRepository.Update(id, entity); return(Ok(entity)); }
public ActionResult DeleteTask(int id) { if (AuthenticationManager.LoggedUser == null) { return(RedirectToAction("Login", "Home")); } TasksRepository tasksRepository = new TasksRepository(new TaskManagerDb()); Task task = tasksRepository.GetById(id); tasksRepository.Delete(task); return(RedirectToAction("Index", "TasksManager")); }
public void ChangeStatus(int taskId) { TasksRepository tasksRepository = new TasksRepository("tasks.txt"); Task task = tasksRepository.GetById(taskId); task.LastModified = DateTime.Now.Date; Console.Write("New task status: "); var isDone = Console.ReadLine(); if (!string.IsNullOrEmpty(isDone)) { task.IsDone = bool.Parse(isDone); } tasksRepository.Save(task); Console.WriteLine("Task saved successfully."); Console.ReadKey(true); }
private void GiveHoursWorkedOnTask() { Console.Clear(); TaskHoursWorked taskHoursWorked = new TaskHoursWorked(); taskHoursWorked.UserId = AuthenticationService.LoggedUser.Id; Console.WriteLine("Give hours worked on task:"); Console.Write("Task Id: "); taskHoursWorked.TaskId = Convert.ToInt32(Console.ReadLine()); taskHoursWorked.UserId = AuthenticationService.LoggedUser.Id; TaskData task = new TaskData(); TasksRepository tasksRepository = new TasksRepository("tasks.txt"); task = tasksRepository.GetById(taskHoursWorked.TaskId); if (task.ResponsibleUser == AuthenticationService.LoggedUser.Id) { Console.Write("Hours worked: "); taskHoursWorked.WorkedHours = Convert.ToInt32(Console.ReadLine()); Console.Write("Giving Hours Date: "); taskHoursWorked.givingHoursDate = Console.ReadLine(); TaskHoursWorkedRepository taskHoursWorkedRepository = new TaskHoursWorkedRepository("taskHoursWorked.txt"); taskHoursWorkedRepository.Insert(taskHoursWorked); Console.WriteLine("Task hours worked saved successfully."); Console.ReadKey(true); } else { Console.WriteLine("You can only give hours worked on task you are responsible for"); Console.ReadKey(true); } }
private void ListComments() { Console.Clear(); Console.WriteLine("Get all the commentaries of a task"); Console.Write("Task ID:"); int taskId = Convert.ToInt32(Console.ReadLine()); TasksRepository tasksRespository = new TasksRepository("tasks.txt"); TaskData task = new TaskData(); task = tasksRespository.GetById(taskId); if (task.Creator == AuthenticationService.LoggedUser.Id || task.ResponsibleUser == AuthenticationService.LoggedUser.Id) { ComentaryRepository comentaryRepository = new ComentaryRepository("comentaries.txt"); List <Comentary> comentaries = comentaryRepository.ListAllComments(task.Id); foreach (Comentary comentary in comentaries) { Console.WriteLine("Comentary ID:" + comentary.Id); Console.WriteLine("Task ID: " + comentary.TaskId); Console.WriteLine("Comentator ID: " + comentary.UserId); Console.WriteLine("Comentary: " + comentary.ComentaryText); Console.WriteLine("########################################"); } Console.ReadKey(true); } else { Console.WriteLine("You can see only comments on tasks you created or you are responsible for"); Console.ReadKey(true); } }
public ActionResult TaskDetails(int id) { if (AuthenticationManager.LoggedUser == null) { return(RedirectToAction("Login", "Home")); } TasksRepository tasksRepository = new TasksRepository(new TaskManagerDb()); TimesRepository timesRepository = new TimesRepository(new TaskManagerDb()); CommentsRepository commentsRepository = new CommentsRepository(new TaskManagerDb()); var times = timesRepository.GetAll(); if (times != null) { ViewData["times"] = times.Where(i => i.TaskId == id).ToList(); } else { ViewData["times"] = times; } var comments = commentsRepository.GetAll(); if (comments != null) { ViewData["comments"] = comments.Where(c => c.TaskId == id).ToList(); } else { ViewData["comments"] = comments; } ViewData["task"] = tasksRepository.GetById(id); return(View()); }
private void Delete() { TasksRepository tasksRepository = new TasksRepository("tasks.txt"); Console.Clear(); Console.WriteLine("Delete Task:"); Console.Write("Task Id: "); int taskId = Convert.ToInt32(Console.ReadLine()); TaskData task = tasksRepository.GetById(taskId); if (task == null) { Console.WriteLine("Task not found!"); } else { tasksRepository.Delete(task); Console.WriteLine("Task deleted successfully."); } Console.ReadKey(true); }
public ActionResult Update(int id) { ViewBag.Emp = new SelectList(repemp.GetAll(), "Id", "Last_name"); ViewBag.Status = new SelectList( new List <SelectListItem> { new SelectListItem { Text = "Not Started", Value = "Not Started" }, new SelectListItem { Text = "Delayed", Value = "Delayed" }, new SelectListItem { Text = "Completed", Value = "Completed" }, new SelectListItem { Text = "In the Process", Value = "In the Process" }, }, "Value", "Text"); return(View(repository.GetById(id))); }
private void EditTask() { Console.Clear(); Console.Write("Task ID: "); int taskId = Convert.ToInt32(Console.ReadLine()); TasksRepository tasksRepository = new TasksRepository("tasks.txt"); TaskData task = tasksRepository.GetById(taskId); if (task == null) { Console.Clear(); Console.WriteLine("Task not found."); Console.ReadKey(true); return; } Console.WriteLine("Editing Task"); Console.WriteLine("ID:" + task.Id); Console.WriteLine("Title: " + task.Title); Console.Write("New Title: "); string title = Console.ReadLine(); Console.WriteLine("Description: " + task.Description); Console.Write("New Description :"); string description = Console.ReadLine(); Console.WriteLine("Time: " + task.Time); Console.Write("New Time: "); int time = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Responsible User ID: " + task.ResponsibleUser); Console.Write("New Responsible User: "******"Creator ID: " + task.Creator); Console.Write("New Creator: "); int creator = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Creation Date: " + task.CreationDate); Console.Write("New Creation Date :"); string creationDate = Console.ReadLine(); Console.WriteLine("Last Update Date: " + task.LastUpdateDate); Console.Write("New Last Update Date :"); string lastUpdateDate = Console.ReadLine(); if (!string.IsNullOrEmpty(title)) { task.Title = title; } if (!string.IsNullOrEmpty(description)) { task.Description = description; } task.Time = time; task.ResponsibleUser = responsibleUser; task.Creator = creator; if (!string.IsNullOrEmpty(creationDate)) { task.CreationDate = creationDate; } if (!string.IsNullOrEmpty(lastUpdateDate)) { task.LastUpdateDate = lastUpdateDate; } tasksRepository.Update(task); Console.WriteLine("Task updated successfully."); Console.ReadKey(true); }
private void UpdateState() { Console.Clear(); Console.WriteLine("Update Task State"); Console.Write("Task ID: "); int taskId = Convert.ToInt32(Console.ReadLine()); TasksRepository tasksRepository = new TasksRepository("tasks.txt"); TaskData task = tasksRepository.GetById(taskId); if (task == null) { Console.Clear(); Console.WriteLine("Task not found."); Console.ReadKey(true); return; } if (task.ResponsibleUser == AuthenticationService.LoggedUser.Id || task.Creator == AuthenticationService.LoggedUser.Id) { Console.WriteLine("Editing Task State For (" + task.Title + ": " + task.Description + ")"); Console.WriteLine("ID:" + task.Id); Console.WriteLine("State: " + task.State); Console.Write("New Task State: "); string taskState = Console.ReadLine(); if ((task.ResponsibleUser == AuthenticationService.LoggedUser.Id && taskState.ToLower() == "completed") || (task.Creator == AuthenticationService.LoggedUser.Id && taskState.ToLower() == "waiting")) { task.State = taskState; tasksRepository.Update(task); Console.WriteLine("Task state updated successfully."); Console.WriteLine("Comentary:"); string comentaryText = Console.ReadLine(); Comentary comentary = new Comentary(); comentary.TaskId = task.Id; comentary.UserId = AuthenticationService.LoggedUser.Id; comentary.ComentaryText = comentaryText; ComentaryRepository comentaryRepository = new ComentaryRepository("comentaries.txt"); comentaryRepository.Insert(comentary); Console.WriteLine("Comentary added successfully."); Console.ReadKey(true); } else { Console.WriteLine("You can change the state of a task from \"Completed\" to \"Waiting\" only if you are the creator of the task"); Console.WriteLine("You can change the state of a task from \"Waiting\" to \"Completed\" only if you are the responsible for the task"); Console.ReadKey(true); } } else { Console.WriteLine("You can only change the state of tasks you are responsible for or you have created"); Console.ReadKey(true); } }
public ActionResult GetTask(int id) { var repo = new TasksRepository(_connectionString); return(Json(repo.GetById(id))); }
public void EditTask(Model.Contracts.Task task) { var original = tasksRepository.GetById(t => t.TaskId == task.TaskId); tasksRepository.Update(original, task.AutoMapObject <Model.Contracts.Task, DB.Task>()); }