//Jaimeiris - edits an evaluation that was previously made about a submission
        //If the evaluator asked for a final version of the submission, the system sends an email to the submitter to add a final version of the submission
        public bool editEvaluation(evaluationsubmitted evaluation, usersubmission userSubIn)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    bool isFinalSubmission = context.usersubmission.Where(c => c.finalSubmissionID == userSubIn.initialSubmissionID).FirstOrDefault() == null ?
                        false : (context.usersubmission.Where(d => d.initialSubmissionID == userSubIn.initialSubmissionID).FirstOrDefault() == null ? true : false);
                    usersubmission userSub;

                    evaluationsubmitted dbEvaluation = context.evaluationsubmitteds.Where(c => c.evaluationsubmittedID == evaluation.evaluationsubmittedID).FirstOrDefault();
                    dbEvaluation.deleted = false;
                    //updates evaluation
                    if (evaluation.evaluationName != null || evaluation.evaluationFile != null)
                    {
                        dbEvaluation.evaluationName = evaluation.evaluationName;
                        dbEvaluation.evaluationFile = evaluation.evaluationFile;
                    }
                    dbEvaluation.score = evaluation.score;
                    dbEvaluation.publicFeedback = evaluation.publicFeedback;
                    dbEvaluation.privateFeedback = evaluation.privateFeedback;
                    var evaluatorSub = dbEvaluation.evaluatiorsubmission;
                    //marks evaluator submission as evaluated
                    if (evaluatorSub != null)
                    {
                        dbEvaluation.evaluatiorsubmission.statusEvaluation = "Evaluated";
                    }
                    if (isFinalSubmission)
                    {
                        userSub = context.usersubmission.Where(c => c.finalSubmissionID == userSubIn.initialSubmissionID).FirstOrDefault();
                    }
                    else
                    {
                        userSub = context.usersubmission.Where(c => c.initialSubmissionID == userSubIn.initialSubmissionID).FirstOrDefault();
                        userSub.allowFinalVersion = userSubIn.allowFinalVersion;
                    }
                    context.SaveChanges();
                    //sends email if final version was asked
                    if (userSubIn.allowFinalVersion == true)
                    {
                        String email = null;
                        email = (context.usersubmission.Where(c => c.initialSubmissionID == userSubIn.initialSubmissionID).FirstOrDefault() == null ? null :
                            context.usersubmission.Where(c => c.initialSubmissionID == userSubIn.initialSubmissionID).FirstOrDefault().user.membership.email);
                        if (email == null) email = context.usersubmission.Where(c => c.finalSubmissionID == userSubIn.initialSubmissionID).FirstOrDefault() == null ?
                             null : context.usersubmission.Where(c => c.finalSubmissionID == userSubIn.initialSubmissionID).FirstOrDefault().user.membership.email;

                        try { sendFinalVersionAllowedEmail(email, context.submissions.Where(c => c.submissionID == userSubIn.initialSubmissionID).FirstOrDefault().title); }

                        catch (Exception ex)
                        {
                            Console.Write("SubmissionManager.editEvaluation error " + ex);
                            return false;
                        }
                    }
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.editEvaluation error " + ex);
                return false;
            }
        }
        //Jaimeiris - add an evaluation to a submission.
        //If the evaluator asked for a final version of the submission, the system sends an email to the submitter to add a final version of the submission
        public bool addEvaluation(evaluationsubmitted evaluation, usersubmission usersubIn)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    //Checking if its final or initial submission, here initialSubmissionID is actually the id of the submission evaluated, not necessarily the initial
                    bool isFinalSubmission = context.usersubmission.Where(c => c.finalSubmissionID == usersubIn.initialSubmissionID).FirstOrDefault() == null ?
                        false : (context.usersubmission.Where(d => d.initialSubmissionID == usersubIn.initialSubmissionID).FirstOrDefault() == null ? true : false);
                    usersubmission userSub;
                    //adding the evaluation
                    evaluation.deleted = false;
                    context.evaluationsubmitteds.Add(evaluation);
                    context.SaveChanges();
                    context.evaluatiorsubmissions.Where(c => c.evaluationsubmissionID == evaluation.evaluatiorSubmissionID).FirstOrDefault().statusEvaluation = "Evaluated";
                    context.SaveChanges();
                    if (isFinalSubmission)
                    {
                        userSub = context.usersubmission.Where(c => c.finalSubmissionID == usersubIn.initialSubmissionID).FirstOrDefault();
                    }
                    else
                    {
                        userSub = context.usersubmission.Where(c => c.initialSubmissionID == usersubIn.initialSubmissionID).FirstOrDefault();
                    }
                    userSub.allowFinalVersion = usersubIn.allowFinalVersion;
                    context.SaveChanges();
                    //sends an email notifying the user if the evaluator asked for a final version of the submission
                    if (usersubIn.allowFinalVersion == true)
                    {
                        String email = null;
                        email = (context.usersubmission.Where(c => c.initialSubmissionID == usersubIn.initialSubmissionID).FirstOrDefault() == null ? null :
                            context.usersubmission.Where(c => c.initialSubmissionID == usersubIn.initialSubmissionID).FirstOrDefault().user.membership.email);
                        if (email == null) email = context.usersubmission.Where(c => c.finalSubmissionID == usersubIn.initialSubmissionID).FirstOrDefault() == null ?
                             null : context.usersubmission.Where(c => c.finalSubmissionID == usersubIn.initialSubmissionID).FirstOrDefault().user.membership.email;

                        try { sendFinalVersionAllowedEmail(email, context.submissions.Where(c => c.submissionID == usersubIn.initialSubmissionID).FirstOrDefault().title); }

                        catch (Exception ex)
                        {
                            Console.Write("SubmissionManager.addEvaluation error " + ex);
                            return false;
                        }
                    }

                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.addEvaluation error " + ex);
                return false;
            }
        }