public void Add(Model.Paper p) { Paper paper = new Paper(); paper.Name = p.Title; paper.Resume = p.Resume; paper.Domain = p.Domain; paper.Subdomain = p.Subdomain; paper.Filepath = p.Filepath; paper.EvaluationResult = Enum.GetName(p.Status.GetType(), p.Status); paper.IsEmailSent = false; paper.ConferenceId = p.ConferenceId; paper.UserId = p.Uploader.IdUser; //paper.TopicId get topic by name and conf foreach (Topic topic in _context.Topics) { if (topic.TopicName == p.Topic && topic.ConferenceId == p.ConferenceId) { paper.TopicId = topic.TopicId; break; } } _context.Papers.Add(paper); _context.SaveChanges(); foreach (Author author in p.AdditionalAuthors) { if (_context.AdditionalAuthors.Find(author.IdAuthor) == null) { AdditionalAuthor aa = new AdditionalAuthor(); aa.Affiliation = author.Affiliation; aa.Name = author.Name; aa.PaperId = paper.PaperId; _context.AdditionalAuthors.Add(aa); } } _context.SaveChanges(); }
public void Modify(int paperId, Model.Paper newP) { Paper paper = _context.Papers.Find(paperId); if (paper == null) { return; } paper.Name = newP.Title; paper.Resume = newP.Resume; paper.Domain = newP.Domain; paper.Subdomain = newP.Subdomain; paper.Filepath = newP.Filepath; paper.EvaluationResult = Enum.GetName(newP.Status.GetType(), newP.Status); paper.IsEmailSent = false; paper.ConferenceId = newP.ConferenceId; paper.UserId = newP.Uploader.IdUser; foreach (Author author in newP.AdditionalAuthors) { if (_context.AdditionalAuthors.Find(author.IdAuthor) == null) { AdditionalAuthor aa = new AdditionalAuthor(); aa.Affiliation = author.Affiliation; aa.Name = author.Name; aa.PaperId = paperId; _context.AdditionalAuthors.Add(aa); } } foreach (KeyValuePair <Participant, int> bid in newP.Bids) { //get bid by lucrare, participant add daca nu exista, modify daca exista bool exists = false; foreach (Bid b in _context.Bids) { if (b.PaperId == paperId && b.PCMemberUserId == bid.Key.User.IdUser) { b.BiddingEvaluation = bid.Value; exists = true; break; } } if (!exists) { Bid b = new Bid(); b.BiddingEvaluation = bid.Value; b.PCMemberUserId = bid.Key.User.IdUser; b.PaperId = paperId; b.PCMemberConferenceId = newP.ConferenceId; _context.Bids.Add(b); } } foreach (Model.Review review in newP.Reviews) { //daca nu exista review adauga nou, altfel modifica Review r = _context.Reviews.Find(review.Reviewer.User.IdUser, newP.ConferenceId, newP.Id); if (r == null) { Review rev = new Review(); rev.PCMemberUserId = review.Reviewer.User.IdUser; rev.PCMemberConferenceId = review.Reviewer.ConferenceId; rev.PaperId = paperId; rev.Evaluation = (int)review.Verdict; rev.Recommandations = review.Comments; _context.Reviews.Add(rev); } else { r.Evaluation = (int)review.Verdict; r.Recommandations = review.Comments; } } _context.SaveChanges(); }