Exemplo n.º 1
0
        public ActionResult ReviewersAssignDelete(ReviewersAssignViewModel ram, string reviewerId, int articleId)
        {
            ModelState.Clear();
            ApplicationDbContext dbContext = new ApplicationDbContext();
            var article = dbContext.Articles.Find(ram.Article.ArticleId);
            List <SimpleReviewer>  assigned  = new List <SimpleReviewer>();
            List <ApplicationUser> available = new List <ApplicationUser>();
            ApplicationUser        tempUser;

            //prepare assigned list
            foreach (SimpleReviewer a in ram.AssignedReviewers)
            {
                if (a.Id != reviewerId)
                {
                    tempUser = dbContext.Users.Find(a.Id);
                    assigned.Add(new SimpleReviewer()
                    {
                        Affiliation  = tempUser.Affiliation,
                        Id           = tempUser.Id,
                        Name         = tempUser.Name,
                        Surname      = tempUser.Surname,
                        ReviewStatus = tempUser.AssignedReviews.First(r => r.Reviewer.Id == tempUser.Id).Status
                    });
                }
            }

            var role = dbContext.Roles.SingleOrDefault(m => m.Name == "Admin");

            available = dbContext.Users.Where(m => m.Roles.All(r => r.RoleId != role.Id) && !m.Affiliation.ToLower().Equals(article.MainAuthor.Affiliation.ToLower()) && m.EmailConfirmed).ToList();
            foreach (SimpleReviewer s in assigned)
            {
                var toRemove = available.FirstOrDefault(a => a.Id == s.Id);
                available.Remove(toRemove);
            }
            if (!String.IsNullOrEmpty(ram.SearchPhrase))
            {
                available = available.Where(r => r.Name.ToLower().Contains(ram.SearchPhrase.ToLower()) || r.Surname.ToLower().Contains(ram.SearchPhrase.ToLower()) || r.Affiliation.ToLower().Contains(ram.SearchPhrase.ToLower())).ToList();
            }
            switch (ram.SortBy)
            {
            case UserSortBy.Name:
                available = available.OrderBy(r => r.Name).ToList();
                break;

            case UserSortBy.Surname:
                available = available.OrderBy(r => r.Surname).ToList();
                break;

            case UserSortBy.Affiliation:
                available = available.OrderBy(r => r.Affiliation).ToList();
                break;
            }
            ram.Article            = article;
            ram.AssignedReviewers  = assigned;
            ram.AvailableReviewers = available;

            return(View("ReviewersAssign", ram));
        }
Exemplo n.º 2
0
        public ActionResult ReviewersSearchAssign(ReviewersAssignViewModel ram, int articleId, string[] assignedIds)
        {
            ApplicationDbContext        dbContext = new ApplicationDbContext();
            List <ApplicationUser>      reviewers = new List <ApplicationUser>();
            ReviewersAssignPartialModel rapm      = new ReviewersAssignPartialModel();
            Article article = dbContext.Articles.Find(articleId);

            rapm.ArticleId = articleId;
            var role = dbContext.Roles.SingleOrDefault(m => m.Name == "Admin");

            reviewers = dbContext.Users.Where(m => m.Roles.All(r => r.RoleId != role.Id) && !m.Affiliation.ToLower().Equals(article.MainAuthor.Affiliation.ToLower()) && m.EmailConfirmed).ToList();

            if (assignedIds != null)
            {
                foreach (string id in assignedIds)
                {
                    var toRemove = reviewers.FirstOrDefault(a => a.Id == id);
                    reviewers.Remove(toRemove);
                }
            }


            if (!String.IsNullOrEmpty(ram.SearchPhrase))
            {
                reviewers = reviewers.Where(r => r.Name.ToLower().Contains(ram.SearchPhrase.ToLower()) || r.Surname.ToLower().Contains(ram.SearchPhrase.ToLower()) || r.Affiliation.ToLower().Contains(ram.SearchPhrase.ToLower())).ToList();
            }

            switch (ram.SortBy)
            {
            case UserSortBy.Name:
                reviewers = reviewers.OrderBy(r => r.Name).ToList();
                break;

            case UserSortBy.Surname:
                reviewers = reviewers.OrderBy(r => r.Surname).ToList();
                break;

            case UserSortBy.Affiliation:
                reviewers = reviewers.OrderBy(r => r.Affiliation).ToList();
                break;
            }
            rapm.AvailableReviewers = reviewers.Skip((ram.CurrentPage - 1) * ram.ResultsForPage).Take(ram.ResultsForPage).ToList();
            rapm.MaxPages           = (int)Math.Ceiling((double)reviewers.Count / (double)ram.ResultsForPage);

            return(PartialView("_ReviewersAssign", rapm));
        }
Exemplo n.º 3
0
        private ReviewersAssignViewModel getActualReviewrsAssignModel(int articleId)
        {
            ReviewersAssignViewModel ravm = new ReviewersAssignViewModel();

            ApplicationDbContext dbContext = new ApplicationDbContext();

            ravm.Article           = dbContext.Articles.Find(articleId);
            ravm.AssignedReviewers = new List <SimpleReviewer>();

            foreach (Review r in ravm.Article.Reviews)
            {
                ravm.AssignedReviewers.Add(new SimpleReviewer()
                {
                    Affiliation  = r.Reviewer.Affiliation,
                    Id           = r.Reviewer.Id,
                    Name         = r.Reviewer.Name,
                    Surname      = r.Reviewer.Surname,
                    ReviewStatus = r.Status
                });
            }

            var role = dbContext.Roles.SingleOrDefault(m => m.Name == "Admin");

            ravm.AvailableReviewers = dbContext.Users.Where(m => m.Roles.All(r => r.RoleId != role.Id) && !m.Affiliation.ToLower().Equals(ravm.Article.MainAuthor.Affiliation.ToLower()) && m.EmailConfirmed).ToList();

            foreach (SimpleReviewer s in ravm.AssignedReviewers)
            {
                var toRemove = ravm.AvailableReviewers.FirstOrDefault(a => a.Id == s.Id);
                ravm.AvailableReviewers.Remove(toRemove);
            }

            ravm.AvailableReviewers = ravm.AvailableReviewers.OrderBy(r => r.Surname).ToList();
            ravm.SortBy             = UserSortBy.Name;
            ravm.CurrentPage        = 1;
            ravm.NumberOfPages      = (int)Math.Ceiling((double)ravm.AvailableReviewers.Count / (double)10);
            ravm.ResultsForPage     = 10;
            return(ravm);
        }
Exemplo n.º 4
0
        public ActionResult ReviewersAssign(ReviewersAssignViewModel ram)
        {
            ApplicationDbContext dbContext = new ApplicationDbContext();
            var article = dbContext.Articles.Find(ram.Article.ArticleId);
            List <ApplicationUser> assignedReviewers = new List <ApplicationUser>();

            if (ram.AssignedReviewers != null)
            {
                foreach (SimpleReviewer user in ram.AssignedReviewers)
                {
                    assignedReviewers.Add(dbContext.Users.Find(user.Id));
                }
            }
            switch (article.Status)
            {
            case ArticleStatus.WaitingToAssignReviewers:
            {
                if (assignedReviewers.Count != 2)
                {
                    ram = getActualReviewrsAssignModel(article.ArticleId);
                    ModelState.AddModelError("AssignedReviewers", "You must assign two reviewers for the article.");
                    return(View(ram));
                }
                foreach (ApplicationUser reviewer in assignedReviewers)
                {
                    article.Reviews.Add(new Review()
                        {
                            Reviewer       = reviewer,
                            Status         = ReviewStatus.NotReviewedYet,
                            RelatedArticle = article
                        });
                }
                article.Status = ArticleStatus.ReviewersAssigned;
                dbContext.SaveChangesAsync();
                break;
            }

            case ArticleStatus.ReviewersAssigned:
            {
                if (assignedReviewers.Count != 2)
                {
                    ram = getActualReviewrsAssignModel(article.ArticleId);
                    ModelState.AddModelError("AssignedReviewers", "You must assign two reviewers for the article.");
                    return(View(ram));
                }

                //Delete previous reviewers
                List <Review> tempReviewsList = article.Reviews.ToList();
                foreach (Review review in tempReviewsList)
                {
                    dbContext.Reviews.Remove(review);
                }
                //Add new reviewers
                foreach (ApplicationUser reviewer in assignedReviewers)
                {
                    article.Reviews.Add(new Review()
                        {
                            Reviewer       = reviewer,
                            Status         = ReviewStatus.NotReviewedYet,
                            RelatedArticle = article
                        });
                }
                break;
            }

            case ArticleStatus.NewReviewerNeeded:
            {
                if (assignedReviewers.Count != 3)
                {
                    ram = getActualReviewrsAssignModel(article.ArticleId);
                    ModelState.AddModelError("AssignedReviewers", "You must only one additional reviewer");
                    return(View(ram));
                }

                foreach (ApplicationUser reviewer in assignedReviewers)
                {
                    if (article.Reviews.Any(r => r.Reviewer.Id != reviewer.Id))
                    {
                        article.Reviews.Add(new Review()
                            {
                                Reviewer       = reviewer,
                                Status         = ReviewStatus.NotReviewedYet,
                                RelatedArticle = article
                            });
                    }
                }
                article.Status = ArticleStatus.NewReviewerReview;
                dbContext.SaveChangesAsync();
                break;
            }
            }
            return(RedirectToAction("ReviewersAssign", new { articleId = ram.Article.ArticleId }));
        }
Exemplo n.º 5
0
        public ActionResult ReviewersAssign(int articleId)
        {
            ReviewersAssignViewModel ravm = getActualReviewrsAssignModel(articleId);

            return(View(ravm));
        }