//Jaimeiris - deletes a submission
        public Submission deleteSubmission(long subID)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    usersubmission i = null;//previous submission
                    Submission prevSub = null;
                    submission sub = context.submissions.Where(c => c.submissionID == subID).FirstOrDefault();
                    bool isFinalVersion = context.usersubmission.Where(c => c.deleted == false && c.finalSubmissionID == subID).FirstOrDefault() == null ? false : true;
                    //if its a final version deletes only the final version of the submission, not the previous one
                    if (isFinalVersion)
                    {
                        i = context.usersubmission.Where(c => c.finalSubmissionID == subID).FirstOrDefault();

                        long submissionID = i.submission1 == null ? -1 : i.submission1.submissionID;
                        String submissionTypeName = i.submission1 == null ? null : i.submission1.submissiontype.name;
                        int submissionTypeID = i.submission1 == null ? -1 : i.submission1.submissionTypeID;
                        String submissionTitle = i.submission1 == null ? null : i.submission1.title;
                        int topiccategoryID = i.submission1 == null ? -1 : i.submission1.topicID;
                        String status = i.submission1 == null ? null : i.submission1.status;
                        bool isEvaluated = (context.evaluatiorsubmissions.Where(c => c.deleted == false && c.submissionID == submissionID).FirstOrDefault() == null ? null : context.evaluatiorsubmissions.Where(c => c.deleted == false && c.submissionID == submissionID).FirstOrDefault().statusEvaluation) == "Evaluated" ? true : false;
                        bool isAssigned = context.evaluatiorsubmissions.Where(c => c.deleted == false && c.submissionID == submissionID).FirstOrDefault() == null ? false : true;
                        bool isFinalSubmission = false;
                        bool finalSubmissionAllowed = (i.allowFinalVersion == null ? false : i.allowFinalVersion) == false ? false : true;

                        prevSub = new Submission(submissionID, submissionTypeName, submissionTypeID, submissionTitle,
                            topiccategoryID, status, isEvaluated, isAssigned, isFinalSubmission, finalSubmissionAllowed);

                        //if submission to be deleted is final version disconnect the final version from the previous one
                        var theFinalSub = context.usersubmission.Where(c => c.deleted == false && c.finalSubmissionID == subID).FirstOrDefault();
                        theFinalSub.finalSubmissionID = null;
                    }

                    //delete pdf files
                    if (sub.documentssubmitteds != null)
                    {
                        foreach (var s in sub.documentssubmitteds)
                        {
                            s.deleted = true;
                        }
                    }
                    //delete submission
                    sub.deleted = true;
                    //delete user submissions only if submission to be deleted is not a final version of a submission
                    if (sub.usersubmissions.FirstOrDefault() != null && isFinalVersion == false)
                    {
                        sub.usersubmissions.FirstOrDefault().deleted = true;
                    }
                    if (sub.usersubmissions1.FirstOrDefault() != null && isFinalVersion == false)
                    {
                        sub.usersubmissions1.FirstOrDefault().deleted = true;
                    }
                    //if submission is pannel delete extra fields
                    if (sub.submissionTypeID == 3 && sub.panels != null)
                    {
                        foreach (var s in sub.panels)
                        {
                            s.deleted = true;
                        }
                    }
                    //if submission is workshop delete extra fields
                    if (sub.submissionTypeID == 5 && sub.workshops != null)
                    {
                        foreach (var s in sub.workshops)
                        {
                            s.deleted = true;
                        }
                    }
                    //if submission has an evaluator assigned (can only happen when an admin or committe evaluator deletes it)
                    List<evaluatiorsubmission> evaluatorSubmission = context.evaluatiorsubmissions.Where(c => c.submissionID == subID && c.deleted == false).ToList();
                    foreach (evaluatiorsubmission evalSub in evaluatorSubmission)
                    {
                        evalSub.deleted = true;
                    }

                    context.SaveChanges();

                    return prevSub;
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.deleteSubmission error " + ex);
                return null;
            }
        }
        //Jaimeiris - This adds the submission when it is added by an administrator
        public Submission addSubmissionByAdmin(usersubmission usersubTA, submission submissionToAdd, panel pannelToAdd, workshop workshopToAdd)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    submission sub = new submission();
                    //for all types of submissions
                    //table submission
                    sub.topicID = submissionToAdd.topicID;
                    sub.submissionTypeID = submissionToAdd.submissionTypeID;
                    sub.submissionAbstract = submissionToAdd.submissionAbstract;
                    sub.title = submissionToAdd.title;
                    sub.status = "Pending";
                    sub.creationDate = DateTime.Now;
                    sub.deleted = false;
                    sub.byAdmin = true;
                    context.submissions.Add(sub);
                    context.SaveChanges();
                    //table usersubmission
                    long submissionID = sub.submissionID;
                    usersubmission usersub = new usersubmission();
                    usersub.userID = usersubTA.userID;
                    usersub.initialSubmissionID = submissionID;
                    usersub.allowFinalVersion = false;
                    usersub.deleted = false;
                    usersub.finalSubmissionID = null;
                    context.usersubmission.Add(usersub);
                    context.SaveChanges();
                    //automatically apply user
                    user user = context.users.Where(c => c.userID == usersubTA.userID).FirstOrDefault();
                    user.hasApplied = true;
                    context.SaveChanges();

                    /*/table documents submitted
                    if (submissionToAdd.submissionTypeID != 4)
                    {
                        documentssubmitted subDocs = new documentssubmitted();

                        foreach (var doc in submissionToAdd.documentssubmitteds)
                        {
                            subDocs.submissionID = submissionID;
                            subDocs.documentName = doc.documentName;
                            subDocs.document = doc.document;
                            subDocs.deleted = false;
                            context.documentssubmitteds.Add(subDocs);
                            context.SaveChanges();
                        }
                    }*/

                    //table pannels
                    if (submissionToAdd.submissionTypeID == 3 && pannelToAdd != null)
                    {
                        panel subPanel = new panel();
                        subPanel.submissionID = submissionID;
                        subPanel.panelistNames = pannelToAdd.panelistNames;
                        subPanel.plan = pannelToAdd.plan;
                        subPanel.guideQuestion = pannelToAdd.guideQuestion;
                        subPanel.formatDescription = pannelToAdd.formatDescription;
                        subPanel.necessaryEquipment = pannelToAdd.necessaryEquipment;
                        subPanel.deleted = false;
                        context.panels.Add(subPanel);
                        context.SaveChanges();
                    }
                    //table workshop
                    if (submissionToAdd.submissionTypeID == 5 && workshopToAdd != null)
                    {
                        workshop subWorkshop = new workshop();
                        subWorkshop.submissionID = submissionID;
                        subWorkshop.duration = workshopToAdd.duration;
                        subWorkshop.delivery = workshopToAdd.delivery;
                        subWorkshop.plan = workshopToAdd.plan;
                        subWorkshop.necessary_equipment = workshopToAdd.necessary_equipment;
                        subWorkshop.deleted = false;
                        context.workshops.Add(subWorkshop);
                        context.SaveChanges();
                    }

                    Submission addedSub = new Submission
                    {
                        submissionID = submissionID,
                        submissionTypeName = getSubmissionTypeName(sub.submissionTypeID),
                        submissionTypeID = sub.submissionTypeID,
                        submissionTitle = sub.title,
                        topiccategoryID = sub.topicID,
                        status = sub.status,
                        isEvaluated = false,
                        isFinalSubmission = false
                    };
                    return addedSub;
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.addSubmission error " + ex);
                return null;
            }
        }
        //Jaimeiris - changes the status of a submission
        //if submission was accepted the acceptance status of the submitter changes to accepted too.
        public Submission changeSubmissionStatus(long submissionID, string newStatus)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    bool changedAcceptanceStatus = false;
                    submission sub = context.submissions.Where(c => c.submissionID == submissionID && c.deleted == false).FirstOrDefault();
                    sub.status = newStatus;
                    context.SaveChanges();
                    if (newStatus == "Accepted")
                    {
                        user u = sub.usersubmissions1.Where(c => c.deleted == false).FirstOrDefault() == null ? null : sub.usersubmissions1.Where(c => c.deleted == false).FirstOrDefault().user;

                        if (u == null)
                            u = sub.usersubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ? null : sub.usersubmissions.Where(c => c.deleted == false).FirstOrDefault().user;

                        u.acceptanceStatus = "Accepted";
                        u.hasApplied = true;
                        context.SaveChanges();
                        changedAcceptanceStatus = true;
                    }
                    Submission subAltered = new Submission();
                    subAltered.changedAcceptanceStatus = changedAcceptanceStatus;
                    subAltered.submissionID = sub.submissionID;
                    subAltered.status = newStatus;
                    //send email
                    String email = null;
                    email = sub.usersubmissions1.Where(c => c.deleted == false).FirstOrDefault() == null ? null : sub.usersubmissions1.Where(c => c.deleted == false).FirstOrDefault().user.membership.email;
                    if (email == null) email = sub.usersubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ? null : sub.usersubmissions.Where(c => c.deleted == false).FirstOrDefault().user.membership.email;
                    try { sendSubmissionUpdateEmail(email, sub.title, sub.status, changedAcceptanceStatus); }

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

                    return subAltered;
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.changeSubmissionStatus error " + ex);
                return null;
            }
        }
        //Jaimeiris - adds a final submission to a existing submission, this is when the submitter os not an administrator
        //Also removes the evaluator submission assignment for the relations for which the evaluations have not been added and sends an email to the evaluators informing them that they no longer have to evaluate said submission
        public Submission addFinalSubmission(usersubmission usersubTA, submission submissionToAdd, documentssubmitted submissionDocuments, panel pannelToAdd, workshop workshopToAdd)
        {
            try
            {
                String email = "";
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    submission sub = new submission();
                    //for all types of submissions
                    //table submission
                    sub.topicID = submissionToAdd.topicID;
                    sub.submissionTypeID = submissionToAdd.submissionTypeID;
                    sub.submissionAbstract = submissionToAdd.submissionAbstract;
                    sub.title = submissionToAdd.title;
                    sub.status = "Pending";
                    sub.creationDate = DateTime.Now;
                    sub.deleted = false;
                    sub.byAdmin = false;
                    context.submissions.Add(sub);
                    context.SaveChanges();
                    //table usersubmission
                    long finalSubmissionID = sub.submissionID;
                    usersubmission usersub = context.usersubmission.Where(c => c.initialSubmissionID == usersubTA.initialSubmissionID && c.deleted == false).FirstOrDefault();
                    usersub.finalSubmissionID = finalSubmissionID;
                    context.SaveChanges();

                    //table documents submitted
                    if (submissionToAdd.submissionTypeID != 4)
                    {
                        documentssubmitted subDocs = new documentssubmitted();

                        List<documentssubmitted> prevDocuments = context.documentssubmitteds.Where(d => d.submissionID == usersubTA.initialSubmissionID && d.deleted != true).Select(d => d).ToList();

                        foreach (var doc in prevDocuments)
                        {

                            int count = submissionToAdd.documentssubmitteds.Where(d => d.documentssubmittedID == doc.documentssubmittedID).Count();
                            if (count != 0)
                            {
                                var newDoc = new documentssubmitted();
                                newDoc.submissionID = finalSubmissionID;
                                newDoc.documentName = doc.documentName;
                                newDoc.document = doc.document;
                                newDoc.deleted = false;
                                context.documentssubmitteds.Add(newDoc);
                                context.SaveChanges();
                            }

                        }
                    }

                    //table pannels
                    if (submissionToAdd.submissionTypeID == 3 && pannelToAdd != null)
                    {
                        panel subPanel = new panel();
                        subPanel.submissionID = finalSubmissionID;
                        subPanel.panelistNames = pannelToAdd.panelistNames;
                        subPanel.plan = pannelToAdd.plan;
                        subPanel.guideQuestion = pannelToAdd.guideQuestion;
                        subPanel.formatDescription = pannelToAdd.formatDescription;
                        subPanel.necessaryEquipment = pannelToAdd.necessaryEquipment;
                        subPanel.deleted = false;
                        context.panels.Add(subPanel);
                        context.SaveChanges();
                    }
                    //table workshop
                    if (submissionToAdd.submissionTypeID == 5 && workshopToAdd != null)
                    {
                        workshop subWorkshop = new workshop();
                        subWorkshop.submissionID = finalSubmissionID;
                        subWorkshop.duration = workshopToAdd.duration;
                        subWorkshop.delivery = workshopToAdd.delivery;
                        subWorkshop.plan = workshopToAdd.plan;
                        subWorkshop.necessary_equipment = workshopToAdd.necessary_equipment;
                        subWorkshop.deleted = false;
                        context.workshops.Add(subWorkshop);
                        context.SaveChanges();
                    }

                    //Delete connection between previous submissions and evaluators that have not evaluated them yet,
                    //since these will not be taken into consideration for the avg score of the final submission
                    List<evaluatiorsubmission> TBD = context.evaluatiorsubmissions.Where(c => c.submissionID == usersubTA.initialSubmissionID && c.statusEvaluation != "Evaluated" && c.deleted == false).ToList();
                    foreach (var assignment in TBD)
                    {
                        //quitando el assignment de submission y evaluator del intial submission a los q aun no han evaluado, se les envia un email al evaluador de que no esta asignado.
                        assignment.deleted = true;

                        try
                        {
                            email = assignment.evaluator.user.membership.email;//evaluator email
                            String subject = "Caribbean Celebration of Women in Computing Assignment Deletion";
                            String messageBody = "Greetings, \n\n " +
                                "The request to evaluate the submission with title " + assignment.submission.title + " has been removed. It is no longer required for you to evaluate said submission.  To view all of your assigned submission please login to the system through the following link: \n\n" +
                                "http://136.145.116.238/#/Login/Log" + ".";
                            sendAssignmentEmail(email, subject, messageBody); //inform evaluator of deleted assignment via email
                        }

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

                    }
                    context.SaveChanges();

                    Submission addedSub = new Submission
                    {
                        submissionID = finalSubmissionID,
                        submissionTypeName = getSubmissionTypeName(sub.submissionTypeID),
                        submissionTypeID = sub.submissionTypeID,
                        submissionTitle = sub.title,
                        topiccategoryID = sub.topicID,
                        status = sub.status,
                        isEvaluated = false,
                        isFinalSubmission = true
                    };
                    return addedSub;
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.addSubmission error " + ex);
                return null;
            }
        }
        //Jaimeiris - adds a final submission when the admins adds it
        public Submission postAdminFinalSubmission(usersubmission usersubTA, submission submissionToAdd, documentssubmitted submissionDocuments, panel pannelToAdd, workshop workshopToAdd)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    submission sub = new submission();
                    //for all types of submissions
                    //table submission
                    sub.topicID = submissionToAdd.topicID;
                    sub.submissionTypeID = submissionToAdd.submissionTypeID;
                    sub.submissionAbstract = submissionToAdd.submissionAbstract;
                    sub.title = submissionToAdd.title;
                    sub.status = "Pending";
                    sub.creationDate = DateTime.Now;
                    sub.deleted = false;
                    sub.byAdmin = true;
                    context.submissions.Add(sub);
                    context.SaveChanges();
                    //table usersubmission
                    long finalSubmissionID = sub.submissionID;
                    usersubmission usersub = context.usersubmission.Where(c => c.initialSubmissionID == usersubTA.initialSubmissionID && c.deleted == false).FirstOrDefault();
                    usersub.finalSubmissionID = finalSubmissionID;
                    context.SaveChanges();

                    //table documents submitted
                    if (submissionToAdd.submissionTypeID != 4)
                    {
                        documentssubmitted subDocs = new documentssubmitted();

                        List<documentssubmitted> prevDocuments = context.documentssubmitteds.Where(d => d.submissionID == usersubTA.initialSubmissionID && d.deleted != true).Select(d => d).ToList();

                        foreach (var doc in prevDocuments)
                        {

                            int count = submissionToAdd.documentssubmitteds.Where(d => d.documentssubmittedID == doc.documentssubmittedID).Count();
                            if (count != 0)
                            {
                                var newDoc = new documentssubmitted();
                                newDoc.submissionID = finalSubmissionID;
                                newDoc.documentName = doc.documentName;
                                newDoc.document = doc.document;
                                newDoc.deleted = false;
                                context.documentssubmitteds.Add(newDoc);
                                context.SaveChanges();
                            }

                        }
                    }

                    //table pannels
                    if (submissionToAdd.submissionTypeID == 3 && pannelToAdd != null)
                    {
                        panel subPanel = new panel();
                        subPanel.submissionID = finalSubmissionID;
                        subPanel.panelistNames = pannelToAdd.panelistNames;
                        subPanel.plan = pannelToAdd.plan;
                        subPanel.guideQuestion = pannelToAdd.guideQuestion;
                        subPanel.formatDescription = pannelToAdd.formatDescription;
                        subPanel.necessaryEquipment = pannelToAdd.necessaryEquipment;
                        subPanel.deleted = false;
                        context.panels.Add(subPanel);
                        context.SaveChanges();
                    }
                    //table workshop
                    if (submissionToAdd.submissionTypeID == 5 && workshopToAdd != null)
                    {
                        workshop subWorkshop = new workshop();
                        subWorkshop.submissionID = finalSubmissionID;
                        subWorkshop.duration = workshopToAdd.duration;
                        subWorkshop.delivery = workshopToAdd.delivery;
                        subWorkshop.plan = workshopToAdd.plan;
                        subWorkshop.necessary_equipment = workshopToAdd.necessary_equipment;
                        subWorkshop.deleted = false;
                        context.workshops.Add(subWorkshop);
                        context.SaveChanges();
                    }

                    //Delete connection between previous submissions and evaluators that have not evaluated them yet,
                    //since these will not be taken into consideration for the avg score of the final submission
                    List<evaluatiorsubmission> TBD = context.evaluatiorsubmissions.Where(c => c.submissionID == usersubTA.initialSubmissionID && c.statusEvaluation != "Evaluated" && c.deleted == false).ToList();
                    foreach (var assignment in TBD)
                    {
                        assignment.deleted = true;
                    }
                    context.SaveChanges();

                    Submission addedSub = new Submission
                    {
                        submissionID = finalSubmissionID,
                        submissionTypeName = getSubmissionTypeName(sub.submissionTypeID),
                        submissionTypeID = sub.submissionTypeID,
                        submissionTitle = sub.title,
                        topiccategoryID = sub.topicID,
                        status = sub.status,
                        isEvaluated = false,
                        isFinalSubmission = true
                    };
                    return addedSub;
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.addSubmission error " + ex);
                return null;
            }
        }
        //Jaimeiris - gets the submission to be viewed in the user's profile
        public List<Submission> getUserSubmissions(long userID)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    //get all final submissions
                    List<usersubmission> userFinalSubmissions0 = context.usersubmission.Where(c => c.userID == userID && c.deleted == false && c.finalSubmissionID != null && c.submission.byAdmin == false).ToList();
                    List<Submission> userFinalSubmissions = new List<Submission>();
                    foreach (var i in userFinalSubmissions0)
                    {
                        Submission finalSub = new Submission
                        {
                            submissionID = i.submission == null ? -1 : i.submission.submissionID,
                            firstName = i.user.firstName,
                            lastName = i.user.lastName,
                            email = i.user.membership.email,
                            submissionTypeName = i.submission == null ? null : i.submission.submissiontype.name,
                            submissionTypeID = i.submission == null ? -1 : i.submission.submissionTypeID,
                            submissionTitle = i.submission == null ? null : i.submission.title,
                            topiccategoryID = i.submission == null ? -1 : i.submission.topicID,
                            status = i.submission == null ? null : i.submission.status,
                            templateName = i.submission.templatesubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ?
                            null : i.submission.templatesubmissions.Where(c => c.deleted == false).FirstOrDefault().template.name,
                            templateID = i.submission.templatesubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ?
                            -1 : i.submission.templatesubmissions.Where(c => c.deleted == false).FirstOrDefault().templateID,
                            isEvaluated = (i.submission.evaluatiorsubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ? null : i.submission.evaluatiorsubmissions.Where(c => c.deleted == false).FirstOrDefault().statusEvaluation) == "Evaluated" ? true : false,
                            isAssigned = i.submission.evaluatiorsubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ? false : true,
                            isFinalSubmission = true
                        };
                        userFinalSubmissions.Add(finalSub);
                    }
                    //get all submissions that do no have a final submission
                    List<Submission> userSubmissions = new List<Submission>();
                    List<usersubmission> userSubs = context.usersubmission.Where(c => c.userID == userID && c.deleted == false && c.finalSubmissionID == null && c.submission1.byAdmin == false).ToList();
                    foreach (var i in userSubs)
                    {
                        Submission sub = new Submission
                        {
                            submissionID = i.submission1 == null ? -1 : i.submission1.submissionID,
                            submissionTypeName = i.submission1 == null ? null : i.submission1.submissiontype.name,
                            submissionTypeID = i.submission1 == null ? -1 : i.submission1.submissionTypeID,
                            submissionTitle = i.submission1 == null ? null : i.submission1.title,
                            topiccategoryID = i.submission1 == null ? -1 : i.submission1.topicID,
                            status = i.submission1 == null ? null : i.submission1.status,
                            isEvaluated = (i.submission1.evaluatiorsubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ? null : i.submission1.evaluatiorsubmissions.Where(c => c.deleted == false).FirstOrDefault().statusEvaluation) == "Evaluated" ? true : false,
                            isAssigned = i.submission1.evaluatiorsubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ? false : true,
                            isFinalSubmission = false,
                            finalSubmissionAllowed = (i.allowFinalVersion == null ? false : i.allowFinalVersion) == false ? false : true
                        };
                        userSubmissions.Add(sub);
                    }

                    foreach (Submission final in userFinalSubmissions)
                    {
                        userSubmissions.Add(final);
                    }
                    return userSubmissions.OrderBy(x => x.submissionTitle).ToList();
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.getUserSubmissions error " + ex);
                return null;
            }
        }
        //Jaimeiris - gets the list of the submissions assigned to the evaluator with the userID that matches the userID sent in the parameter
        public SubmissionPagingQuery getAssignedSubmissions(long userID, int index)
        {
            SubmissionPagingQuery page = new SubmissionPagingQuery();
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {
                    int pageSize = 10;
                    //gets all final evaluations assigned to the given evaluator
                    List<Submission> assignedFinalSubmissions = new List<Submission>();
                    //List<evaluatiorsubmission> finalevs = context.evaluatiorsubmissions.Where(c => c.evaluator.userID == userID && c.deleted == false && c.submission.usersubmissions.Where(d => d.deleted == false).FirstOrDefault() != null).ToList();

                    List<evaluatiorsubmission> finalevs = (from e in context.evaluators
                                                           from s in context.submissions
                                                           from es in context.evaluatiorsubmissions
                                                           from us in context.usersubmission
                                                           where (es.evaluatorID == e.evaluatorsID && es.submissionID == s.submissionID && s.submissionID == us.finalSubmissionID && e.userID == userID && es.deleted == false && us.deleted == false)
                                                           select es).ToList();

                    foreach (var i in finalevs)
                    {
                        Submission subEv = new Submission
                        {
                            submissionID = i.submissionID,
                            evaluatorID = i.evaluatorID,
                            userType = i.submission.usersubmissions.Where(c => c.deleted == false).FirstOrDefault() == null ? null : i.submission.usersubmissions.Where(c => c.deleted == false).FirstOrDefault().user.usertype.userTypeName,
                            submissionTitle = i.submission.title,
                            topic = i.submission.topiccategory.name,
                            isEvaluated = (i.evaluationsubmitteds.Where(c => c.deleted == false).FirstOrDefault() == null ? false : true),
                            isFinalSubmission = true
                        };
                        assignedFinalSubmissions.Add(subEv);
                    }

                    //gets all non-final the evaluations assigned to the given evaluator
                    List<Submission> assignedSubmissions = new List<Submission>();

                    //List<evaluatiorsubmission> evsub = context.evaluatiorsubmissions.Where(c => c.evaluator.userID == userID && c.deleted == false && c.submission.usersubmissions1.Where(d => d.deleted == false).FirstOrDefault() != null).ToList();
                    List<evaluatiorsubmission> evsub = (from e in context.evaluators
                                                        from s in context.submissions
                                                        from es in context.evaluatiorsubmissions
                                                        from us in context.usersubmission
                                                        where (es.evaluatorID == e.evaluatorsID && es.submissionID == s.submissionID && s.submissionID == us.initialSubmissionID && e.userID == userID && es.deleted == false && us.deleted == false)
                                                        select es).ToList();
                    foreach (var i in evsub)
                    {
                        Submission theSub = new Submission
                        {
                            submissionID = i.submissionID,
                            evaluatorID = i.evaluatorID,
                            userType = i.submission.usersubmissions1.Where(c => c.deleted == false).FirstOrDefault() == null ? null : i.submission.usersubmissions1.Where(c => c.deleted == false).FirstOrDefault().user.usertype.userTypeName,
                            submissionTitle = i.submission.title,
                            topic = i.submission.topiccategory.name,
                            isEvaluated = (i.evaluationsubmitteds.Where(c => c.deleted == false).FirstOrDefault() == null ? false : true),
                            isFinalSubmission = false
                        };
                        assignedSubmissions.Add(theSub);
                    }
                    //merge list of final submissions with non-final submissions
                    foreach (var finalSub in assignedFinalSubmissions)
                    {
                        assignedSubmissions.Add(finalSub);
                    }
                    //submissions are ordered  by title
                    assignedSubmissions = assignedSubmissions.OrderBy(n => n.submissionTitle).ToList();
                    page.rowCount = assignedSubmissions.Count();
                    if (page.rowCount > 0)
                    {
                        page.maxIndex = (int)Math.Ceiling(page.rowCount / (double)pageSize);
                        List<Submission> submissionPage = assignedSubmissions.Skip(pageSize * index).Take(pageSize).ToList(); //Skip past rows and take new elements
                        page.results = submissionPage;
                    }

                    return page;
                }
            }
            catch (Exception ex)
            {
                Console.Write("SubmissionManager.getAssignedSubmissions error " + ex);
                return null;
            }
        }
        //Jaimeiris - edits a submission
        public Submission editSubmission(submission submissionToEdit, panel pannelToEdit, workshop workshopToEdit)
        {
            try
            {
                using (conferenceadminContext context = new conferenceadminContext())
                {

                    submission sub = context.submissions.Where(c => c.submissionID == submissionToEdit.submissionID).FirstOrDefault();
                    //for all types of submissions
                    //table submission
                    sub.topicID = submissionToEdit.topicID;
                    sub.submissionAbstract = submissionToEdit.submissionAbstract;
                    sub.title = submissionToEdit.title;
                    context.SaveChanges();

                    //table documents submitted
                    if (submissionToEdit.submissionTypeID != 4)
                    {
                        documentssubmitted subDocs = new documentssubmitted();

                        List<documentssubmitted> prevDocuments = context.documentssubmitteds.Where(d => d.submissionID == submissionToEdit.submissionID && d.deleted != true).Select(d => d).ToList();

                        foreach (var doc in prevDocuments)
                        {

                            int count = submissionToEdit.documentssubmitteds.Where(d => d.documentssubmittedID == doc.documentssubmittedID).Count();
                            if (count == 0)
                            {
                                doc.deleted = true;
                                context.SaveChanges();
                            }

                        }
                    }

                    //table pannels
                    if (sub.submissionTypeID == 3 && pannelToEdit != null)
                    {
                        panel subPanel = context.panels.Where(c => c.submissionID == sub.submissionID).FirstOrDefault();
                        subPanel.panelistNames = pannelToEdit.panelistNames;
                        subPanel.plan = pannelToEdit.plan;
                        subPanel.guideQuestion = pannelToEdit.guideQuestion;
                        subPanel.formatDescription = pannelToEdit.formatDescription;
                        subPanel.necessaryEquipment = pannelToEdit.necessaryEquipment;
                        context.SaveChanges();
                    }
                    //table workshop
                    if (sub.submissionTypeID == 5 && workshopToEdit != null)
                    {
                        workshop subWorkshop = context.workshops.Where(c => c.submissionID == sub.submissionID).FirstOrDefault();
                        subWorkshop.duration = workshopToEdit.duration;
                        subWorkshop.delivery = workshopToEdit.delivery;
                        subWorkshop.plan = workshopToEdit.plan;
                        subWorkshop.necessary_equipment = workshopToEdit.necessary_equipment;
                        context.SaveChanges();
                    }
                    Submission editedSub = new Submission
                    {
                        submissionID = sub.submissionID,
                        submissionTypeName = getSubmissionTypeName(sub.submissionTypeID),
                        submissionTypeID = sub.submissionTypeID,
                        submissionTitle = sub.title,
                        topiccategoryID = sub.topicID
                    };

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