예제 #1
0
        public ActionResult Save(ReviewerFormViewModel vm)
        {
            var proposal = vm.Proposal;

            proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id);
            if (proposal == null || proposal.Submitted)
            {
                return(HttpNotFound());
            }
            var reviewer = vm.Reviewer;

            if (!ModelState.IsValid)
            {
                return(View("Form", reviewer));
            }

            if (reviewer.Id == 0)
            {
                _context.Reviewers.Add(reviewer);
                ExternalReview_Reviewer err = new ExternalReview_Reviewer();
                err.Reviewer       = reviewer;
                err.ExternalReview = proposal.ExternalReview;
                _context.ExternalReview_Reviewer.Add(err);
            }
            else
            {
                var reviewerInDb = _context.Reviewers.SingleOrDefault(m => m.Id == reviewer.Id);
                reviewerInDb.Name        = reviewer.Name;
                reviewerInDb.Affiliation = reviewer.Affiliation;
                reviewerInDb.Address     = reviewer.Address;
                reviewerInDb.Email       = reviewer.Email;
                reviewerInDb.Telephone   = reviewer.Telephone;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "ExternalReview", new { id = proposal.Id }));
        }
예제 #2
0
        public ActionResult Save(ReviewerFormViewModel vm)
        {
            var proposal = vm.Proposal;

            proposal = _context.Proposals.SingleOrDefault(m => m.Id == proposal.Id);
            if (proposal == null || proposal.Submitted)
            {
                return(HttpNotFound());
            }
            if (!proposal.IsEditable(User.Identity.GetUserId()))
            {
                return(HttpNotFound());
            }
            var reviewer = vm.Reviewer;

            if (!ModelState.IsValid)
            {
                return(View("Form", reviewer));
            }

            if (reviewer.Id == 0)
            {
                _context.Reviewers.Add(reviewer);
                ExternalReview_Reviewer err = new ExternalReview_Reviewer();
                err.Reviewer       = reviewer;
                err.ExternalReview = proposal.ExternalReview;
                _context.ExternalReview_Reviewer.Add(err);

                var reviewerList = _context.Reviewers.Where(m => m.Email == reviewer.Email).ToList();
                if (reviewerList.Count() >= 1)
                {
                    //do nothing
                }
                else
                {
                    Whitelist wl = new Whitelist();
                    wl.PrimaryRoleId = "6"; //er
                    wl.Email         = reviewer.Email;
                    _context.Whitelists.Add(wl);
                }
            }
            else
            {
                var reviewerInDb = _context.Reviewers.SingleOrDefault(m => m.Id == reviewer.Id);
                reviewerInDb.Name        = reviewer.Name;
                reviewerInDb.Affiliation = reviewer.Affiliation;
                reviewerInDb.Address     = reviewer.Address;

                //if email changed add new record to whitelist. Check if previous reviewer was linked to other proposals. Else delete from whitelist
                if (reviewer.Email != reviewerInDb.Email)
                {
                    //reviewers with the new email
                    var reviewerList = _context.Reviewers.Where(m => m.Email == reviewer.Email).ToList();
                    if (reviewerList.Count() > 0)
                    {
                        //do nothing
                    }
                    else
                    {
                        Whitelist wl = new Whitelist();
                        wl.PrimaryRoleId = "6";     //er
                        wl.Email         = reviewer.Email;
                        _context.Whitelists.Add(wl);
                    }

                    //reviewers with the old email
                    var reviewerOldList = _context.Reviewers.Where(m => m.Email == reviewerInDb.Email).ToList();
                    if (reviewerOldList.Count() > 1)
                    {
                        //do nothing
                    }
                    else
                    {
                        var wlToRemove = _context.Whitelists.SingleOrDefault(m => m.Email == reviewerInDb.Email);
                        _context.Whitelists.Remove(wlToRemove);
                    }
                }

                reviewerInDb.Email     = reviewer.Email;
                reviewerInDb.Telephone = reviewer.Telephone;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "ExternalReview", new { id = proposal.Id }));
        }