private IEnumerable <CommentModel> ToCommentsModels(IEnumerable <Comment> comments) { return(_commentsRepository.GetAll().Select(c => new CommentModel() { Id = c.Id, Author = c.Author, Content = c.Content, Date = c.Date, })); }
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 Index([Bind(Include = "Author, Time, Comment")] CommentViewModel vComment) { var repo = new CommentsRepository(); if (ModelState.IsValid) { if (repo.SaveComment(vComment)) { return(View(repo.GetAll())); } } return(View(repo.GetAll())); }
// // GET: /Comment/ public ActionResult Index(int id) { var commentsRepository = new CommentsRepository(); var commentsList = new List <Comment>(); var commentsFromRepository = commentsRepository .GetAll(comment => comment.AssignmentId == id); //foreach (var comment in commentsFromRepository) //{ // if (comment.AssignmentId == id) // { // commentsList.Add(comment); // } //} ViewBag.AssignmentId = id; var assignmentRepository = new AssignmentRepository(); ViewBag.AssignmentTitle = assignmentRepository.GetById(id).Title; // Navigational Property Demo //var firstComment = commentsList.FirstOrDefault(); //ViewBag.AssignmentTitle = firstComment.Assignment.Title; commentsList.AddRange(commentsFromRepository); return(View(commentsList)); }
// // GET: /Comment/ public ActionResult Index(int id) { var commentsRepository = new CommentsRepository(); var commentsList = new List <Comment>(); var commentsFromRepo = commentsRepository.GetAll(comment => comment.AssignmentId == id); // var commentsFromRepo = commentsRepository.GetAll(); //foreach (var comment in commentsFromRepo) //{ // if (comment.AssignmentId == id) // { // commentsList.Add(comment); // } //} ViewBag.AssignmentId = id; var assignmentRepository = new AssignmentRepository(); ViewBag.AssignmentTitle = assignmentRepository.GetById(id).Title; commentsList.AddRange(commentsFromRepo); return(View(commentsList)); }
public IHttpActionResult GetComments(int id) //LostStuff id ! { try { List <Comment> allCommetns = new List <Comment>(); allCommetns.AddRange(repository.GetAll().Where(x => x.LostStuffId == id)); List <object> result = new List <object>(); var lostStuffName = repo.GetById(id).Name; foreach (var comment in allCommetns) { result.Add(new { comment.Id, comment.UserName, comment.UserId, comment.LostStuffId, comment.Content, lostStuffName } ); } return(Ok(result)); } catch (Exception) { return(BadRequest("Invalid id!")); } }
public void PostsRepository_HasComments() { // Arrange var commentsRepository = new CommentsRepository(new WebClient(new HttpClient())); // Act var result = commentsRepository.GetAll <IList <Comment> >(6); // Assert Assert.True(result.Result.Count > 0); }
public void CommentsRepository_Comments_Only_By_Valid_Id() { // Arrange var commentsRepository = new CommentsRepository(new WebClient(new HttpClient())); // Act var result = commentsRepository.GetAll <IList <Comment> >(-100); // Assert Assert.True(result.Result.Count == 0); }
public void DeleteUser() { Console.Clear(); Console.Write("Enter user id to delete: "); int id = 0; bool isInt = int.TryParse(Console.ReadLine(), out id); while (isInt == false) { Console.WriteLine("Only numbers can be entered for user ID's"); isInt = int.TryParse(Console.ReadLine(), out id); } UsersRepository userRepo = new UsersRepository("users.txt"); if (userRepo.CheckEntityExistence(User => User.Id == id) == false) { Console.WriteLine("No user with that id exists!!"); Console.ReadKey(true); return; } if (id == 1) { Console.WriteLine("You cannot delete the built-in administrator account!!"); Console.ReadKey(true); return; } CommentsRepository commentRepo = new CommentsRepository("comments.txt"); List <Comment> comments = commentRepo.GetAll(Comment => Comment.CreatorId == id); foreach (Comment comment in comments) { commentRepo.Delete(comment); } TasksRepository taskRepo = new TasksRepository("tasks.txt"); List <Task> tasks = taskRepo.GetAll(Task => Task.CreatorId == id || Task.AssigneeId == id); foreach (Task task in tasks) { taskRepo.Delete(task); } List <User> users = userRepo.GetAll(User => User.Id == id); foreach (User user in users) { userRepo.Delete(user); } Console.WriteLine("User successfully deleted!"); Console.ReadKey(true); }
public ActionResult Index(IndexVM model) { UsersRepository repo = new UsersRepository(); PostsRepository postsRepo = new PostsRepository(); CommentsRepository commentsRepo = new CommentsRepository(); model.User = repo.GetById(model.UserId); model.Posts = postsRepo.GetAll(p => p.UserId == model.UserId); model.Comments = commentsRepo.GetAll(c => c.UserId == model.UserId); return(View(model)); }
public ActionResult Details(TaskDetailsVM model) { TasksRepository tasksRepository = new TasksRepository(); model.Item = tasksRepository.GetById(model.Id); if (model == null) { return(RedirectToAction("Index", "Tasks")); } UsersRepository usersRepository = new UsersRepository(); model.Users = usersRepository.GetAll(); CommentsRepository commentsRepo = new CommentsRepository(); LogworksRepository logworkRepo = new LogworksRepository(); model.CommentsPager = model.CommentsPager ?? new PagerVM(); model.CommentsFilter = model.CommentsFilter ?? new CommentsFilterVM(); model.CommentsFilter.Id = model.Id; var filter = model.CommentsFilter.BuildFilter(); model.CommentsPager.Prefix = "CommentsPager"; model.CommentsFilter.Prefix = "CommentsFilter"; model.CommentsPager.ItemsPerPage = model.CommentsPager.ItemsPerPage == 0 ? 5 : model.CommentsPager.ItemsPerPage; model.CommentsPager.PageCount = (int)Math.Ceiling(commentsRepo.Count(filter) / (decimal)model.CommentsPager.ItemsPerPage); model.CommentsPager.PageCount = model.CommentsPager.PageCount == 0 ? 1 : model.CommentsPager.PageCount; model.Comments = commentsRepo.GetAll(filter, model.CommentsPager.CurrentPage, model.CommentsPager.ItemsPerPage); model.LogworksPager = model.LogworksPager ?? new PagerVM(); model.LogworkFilter = model.LogworkFilter ?? new LogworkFilterVM(); model.LogworkFilter.Id = model.Id; var logworkFilter = model.LogworkFilter.BuildFilter(); model.LogworksPager.Prefix = "LogworksPager"; model.LogworkFilter.Prefix = "LogworkFilter"; model.LogworksPager.ItemsPerPage = model.LogworksPager.ItemsPerPage == 0 ? 5 : model.LogworksPager.ItemsPerPage; model.LogworksPager.PageCount = (int)Math.Ceiling(logworkRepo.Count(logworkFilter) / (decimal)model.LogworksPager.ItemsPerPage); model.LogworksPager.PageCount = model.LogworksPager.PageCount == 0 ? 1 : model.LogworksPager.PageCount; model.Logworks = logworkRepo.GetAll(logworkFilter, model.LogworksPager.CurrentPage, model.LogworksPager.ItemsPerPage); return(View(model)); }
// // GET: /Comment/ public ActionResult Index(int id) { var commentsRepository = new CommentsRepository(); var commentsList = new List <Comment>(); var commentsFromRepo = commentsRepository.GetAll(comment => comment.AssignmentId == id); // var commentsFromRepo = commentsRepository.GetAll(); //foreach (var comment in commentsFromRepo) //{ // if (comment.AssignmentId == id) // { // commentsList.Add(comment); // } //} commentsList.AddRange(commentsFromRepo); var assignmentRepository = new AssignmentRepository(); var model = new CommentListViewModel(); model.AssignmentTitle = assignmentRepository.GetById(id).Title; model.AssignmentId = id; foreach (var entity in commentsList) { var commentModel = new CommentViewModel() { Id = entity.Id, AssignmentId = entity.AssignmentId, Content = entity.Content, CreatedAt = entity.CreatedAt, UpdatedAt = entity.UpdatedAt }; model.Comments.Add(commentModel); } return(View(model)); }
public void ViewCommentsForTasksAssignedToMe() { TasksRepository taskRepo = new TasksRepository("tasks.txt"); List <Entity.Task> tasks = taskRepo.GetAll(Task => Task.AssigneeId == AuthenticationService.LoggedUser.Id); if (tasks.Count == 0) { Console.WriteLine("There are no tasks assigned to you yet."); Console.ReadKey(true); return; } CommentsRepository commentRepo = new CommentsRepository("comments.txt"); UsersRepository userRepo = new UsersRepository("users.txt"); foreach (Entity.Task task in tasks) { Console.WriteLine(); Console.WriteLine("#################################"); Console.WriteLine($"Task id: {task.Id}"); Console.WriteLine($"Task title: {task.Title}"); List <Comment> comments = commentRepo.GetAll(Comment => Comment.RelatedTaskId == task.Id); if (comments.Count == 0) { Console.WriteLine($"No comments for task {task.Id}"); } else { foreach (Comment comment in comments) { Console.WriteLine("*********************************"); Console.WriteLine($"Comment Id: {comment.Id}"); List <User> users = userRepo.GetAll(User => User.Id == comment.CreatorId); Console.WriteLine($"Comment creator: {users[0].FullName}"); Console.WriteLine($"Commented on: {comment.CommentDate}"); Console.WriteLine($"Comment text: {comment.CommentText}"); Console.WriteLine("*********************************"); } } Console.WriteLine("#################################"); } Console.ReadKey(true); }
// GET: Comments public ActionResult Index(IndexVM model, int?PostId) { if (PostId != null) { model.PostId = (int)PostId; } CommentsRepository repo = new CommentsRepository(); model.Items = repo.GetAll(m => m.PostId == model.PostId); PostsRepository postsRepo = new PostsRepository(); model.Post = postsRepo.GetById(model.PostId); UsersRepository usersRepo = new UsersRepository(); model.User = usersRepo.GetById(model.UserId); return(View(model)); }
// // GET: /Comment/ public ActionResult Index(int id) { var commentsRepository = new CommentsRepository(); List <Comment> comments = new List <Comment>(); comments.AddRange(commentsRepository .GetAll(comment => comment.AssignmentId == id)); var assignmentRepostory = new AssignmentRepository(); ViewBag.AssignmentTitle = assignmentRepostory.GetById(id).Title; ViewBag.AssignmentId = id; // Navigational Properties example //var firstEntity = comments.FirstOrDefault(); //ViewBag.AssignmentTitle = // firstEntity != null ? firstEntity.Assignment.Title : "No COMMENTS YET"; return(View(comments)); }
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()); }
public IEnumerable <UserCommentDto> AllComments() { return(_commentsRepository.GetAll()); }
public ActionResult Index() { var repo = new CommentsRepository(); return(View(repo.GetAll())); }
// GET: /Comment/ public ActionResult Index() { return(View(repComments.GetAll())); }
internal IEnumerable <Comment> GetAll() { return(_repo.GetAll()); }