public IHttpActionResult GetEmployeeSurveyQuestionsForReview(string id)
        {
            //First get a list of all the questions

            var Survey = new Surveys();

            var surveyObject = new SurveyForList();

            surveyObject.Type = "Annually";

            surveyObject.Period = "2016";

            surveyObject.Survey_For = id;

            //surveyObject.Rater = new Surveys().getSurveyTeamEmployeeList().Where(c => c.AD_User_Name.ToLower() == Generic.GetCurrentLogonUserName().ToLower()).First().Employee;

            //surveyObject.Ratee = id;

            try
            {
                var surveyList = new Surveys().getSurveyForListRaters(surveyObject).Distinct().ToList();

                return(Ok(surveyList.Distinct().ToList()));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public SurveyForList GetSurveyObject(string survey_For)
        {
            var surveyObject = new SurveyForList();

            surveyObject.Type = "Annually";

            surveyObject.Period = "2016";

            return(surveyObject);
        }
        public IHttpActionResult GetSurveysAssignedPerRater(string rater)
        {
            SurveyForList survey = new SurveyForList();

            survey.Type = "Annually";

            survey.Period = "2016";

            try
            {
                var empList = new Surveys().getSurveyForListRaters((survey));

                var employeeSurveyList = new List <SurveyStatus>();

                return(Ok(employeeSurveyList));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IHttpActionResult GetEmployeeInformationBySurvey(string selectedSurveys)
        {
            var Survey = new Surveys();

            var surveyObject = new SurveyForList();

            surveyObject.Type = "Annually";

            surveyObject.Period = "2016";

            var surveyList = new List <SurveyList>();

            var selectedRaterList = selectedSurveys.Split(',');

            for (int i = 0; i < selectedRaterList.Count(); i++)
            {
                surveyObject.Survey_For = selectedRaterList[i];

                var survey = new Surveys().getSurveyForVerifyAllRaters(surveyObject);

                foreach (var item in survey)
                {
                    if (!(surveyList.Where(c => c.Survey_For == item.Rater).Count() > 0))
                    {
                        surveyList.Add(new SurveyList()
                        {
                            Survey_For = item.Rater
                        });
                    }
                }
            }

            surveyList = surveyList.Distinct().ToList();

            string data = JsonConvert.SerializeObject(surveyList);

            return(Ok(data));
        }
        public IHttpActionResult GetEmployeeSurveyQuestionsForraterUpdate(string id)
        {
            var surveyObject = new SurveyForList();

            surveyObject.Type = "Annually";

            surveyObject.Period = "2016";

            surveyObject.Survey_For = id;

            var raterListString = string.Empty;

            var surveyForList = new Surveys().getSurveyForListRaters(surveyObject);


            //foreach (var surveyObj in surveyForList.Distinct().ToList())
            //{
            //    raterListString += surveyObj + ",";

            //}

            //for (int i = 0; i < list.Count; i++)
            //{
            //    list[i].Rater = raterListString;
            //}

            try
            {
                //var surveyList = new Surveys().getSurveyFor(surveyObject);

                return(Ok(surveyForList.Distinct().ToList()));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public ActionResult ExportToPDF(string Survey_For)
        {
            var surveyFor = Request.Form["Survey_For"];

            SurveyForList surveyReportPParameterObject = new SurveyForList();

            surveyReportPParameterObject.Type = "Annually";

            surveyReportPParameterObject.Period = "2016";

            surveyReportPParameterObject.Survey_For = surveyFor;

            RatingReportModel model = new RatingReportModel();

            //model.IncludeRaters = includeRaters;

            model.ReportList = new Surveys().getSurveyForReport(surveyReportPParameterObject);

            var pdf = new PdfResult(model, "ExportToPDF");

            pdf.ViewBag.Title = "360 DEGREE PERFORMANCE REVIEW REPORT Per Rater";

            return(pdf);
        }
        public ActionResult PrintRatingReportPerBusinessUnit(List <SurveyStatus> Survey_ForList, bool includeRaters, string businessUnit)
        {
            if (Survey_ForList.Count() == 0)
            {
                return(Redirect("PrintRatingReport"));
            }

            List <string> itemRow = new List <string>();

            RatingReport reportObject = new RatingReport();

            DataTable dt = new DataTable();

            SurveyForList surveyReportPParameterObject = new SurveyForList();

            surveyReportPParameterObject.Type = "Annually";

            surveyReportPParameterObject.Period = "2016";

            //var tempDirectoryPath = ConfigurationManager.AppSettings["BusinessUnitReportLocation"] + @"" + businessUnit;

            //var files = Directory.GetFiles(tempDirectoryPath, "*.xlsx");

            //if (Directory.Exists(tempDirectoryPath))
            //{
            //    foreach (var item in files)
            //    {
            //        System.IO.File.Delete(item);
            //    }

            //    Directory.Delete(tempDirectoryPath);
            //}

            foreach (var ratee in Survey_ForList)
            {
                surveyReportPParameterObject.Survey_For = ratee.Survey_For;

                List <SurveyStatus> list = new List <SurveyStatus>();


                list.Add(new SurveyStatus()
                {
                    Survey_For = ratee.Survey_For
                });

                var raterList = new List <string>();

                if (!string.IsNullOrWhiteSpace(ratee.Survey_For))
                {
                    dt = new DataTable();

                    var report = new Surveys().getSurveyForReport(surveyReportPParameterObject);

                    if (report.Count() > 0)
                    {
                        ViewBag.ReportList = report;

                        dt = reportObject.GetColumns(dt, report);

                        reportObject.AddHeadings(dt, ratee.Survey_For, report.First().Period);

                        reportObject.AddQuestionHeadings(dt, report);

                        reportObject.AddQuestionAverallMinRating(dt, report);

                        reportObject.AddQuestionAverallMaxRating(dt, report);

                        reportObject.AddQuestionAverageRating(dt, report);

                        dt.Rows.Add(new List <string>().ToArray());

                        //if (includeRaters)
                        //{
                        itemRow.Add("INDIVIDUAL RATER SCORES AND COMMENTS");

                        dt.Rows.Add(itemRow.ToArray());

                        var raters = report.Select(c => c.Rater).AsQueryable().Distinct().ToList();

                        var questionsPerRater = report.Select(c => c.Rater_Comment).AsQueryable().Distinct().ToList();

                        //for (int i = 0; i < report.Select(c => c.Question_ID).AsQueryable().Distinct().ToList().Count; i++)
                        // {
                        foreach (var item in raters)
                        {
                            var record = report.Where(c => c.Rater == item).ToList();

                            reportObject.AddIndividualRaterComment(dt, record, includeRaters, item, report);

                            reportObject.AddIndividualRating(dt, record, includeRaters, item, report);
                        }
                        // }
                        //}
                    }
                }

                if (!string.IsNullOrWhiteSpace(ratee.Survey_For) && dt.Rows.Count > 0)
                {
                    GenerateRatingReportExcelFilePerBusinessUnit(dt, list, includeRaters, businessUnit);
                }
            }



            return(Redirect("PrintRatingReport"));
        }
        //[AccessDeniedAuthorize(Roles = @"FUTUREGROWTH\FG-APP-PAS-ADMIN")]
        public ActionResult PrintRatingReport(string Survey_For)
        {
            var generateBulkReport = false;

            List <SurveyStatus> employeePerBusinessUnit = new List <SurveyStatus>();

            var surveyFor = Request.Form["Survey_For"];

            var includeRaters = Convert.ToBoolean(Request.Form["IncludeRaters"]);

            //Generate report per business unit
            var employeeForList = GetEmployeeList();

            var teamList = new Surveys().getSurveyTeams();

            if (surveyFor == "Performance and Attribution")
            {
                surveyFor = surveyFor.Replace("and", "&");
            }

            var employeeSurveyListPerTeam = teamList.Where(c => c.Team == surveyFor);


            //if this is true then, generate bulk report
            if (employeeSurveyListPerTeam.Count() > 0)
            {
                generateBulkReport = true;

                if (generateBulkReport)
                {
                    employeePerBusinessUnit = employeeForList.Where(c => c.Team_Desc == surveyFor).ToList();
                }

                PrintRatingReportPerBusinessUnit(employeePerBusinessUnit, includeRaters, surveyFor);
            }
            else
            {
                if (string.IsNullOrWhiteSpace(surveyFor))
                {
                    return(View());
                }

                List <string> itemRow = new List <string>();

                RatingReport reportObject = new RatingReport();

                DataTable dt = new DataTable();

                SurveyForList surveyReportPParameterObject = new SurveyForList();

                surveyReportPParameterObject.Type = "Annually";

                surveyReportPParameterObject.Period = "2016";

                surveyReportPParameterObject.Survey_For = surveyFor;

                var raterList = new List <string>();

                if (!string.IsNullOrWhiteSpace(surveyFor))
                {
                    var report = new Surveys().getSurveyForReport(surveyReportPParameterObject);

                    if (report.Count > 0)
                    {
                        ViewBag.ReportList = report;

                        dt = reportObject.GetColumns(dt, report);

                        reportObject.AddHeadings(dt, surveyFor, report.First().Period);

                        reportObject.AddQuestionHeadings(dt, report);

                        reportObject.AddQuestionAverallMinRating(dt, report);

                        reportObject.AddQuestionAverallMaxRating(dt, report);

                        reportObject.AddQuestionAverageRating(dt, report);

                        dt.Rows.Add(new List <string>().ToArray());

                        //if (includeRaters)
                        //{
                        itemRow.Add("INDIVIDUAL RATER SCORES AND COMMENTS");

                        dt.Rows.Add(itemRow.ToArray());

                        var raters = report.Select(c => c.Rater).AsQueryable().Distinct().ToList();

                        var questionsPerRater = report.Select(c => c.Rater_Comment).AsQueryable().Distinct().ToList();

                        // for (int i = 0; i < report.Select(c => c.Question_ID).AsQueryable().Distinct().ToList().Count; i++)
                        // {
                        foreach (var item in raters)
                        {
                            var record = report.Where(c => c.Rater == item).ToList();

                            reportObject.AddIndividualRaterComment(dt, record, includeRaters, item, report);

                            reportObject.AddIndividualRating(dt, record, includeRaters, item, report);
                        }
                        // }
                        //}
                    }
                }

                if (!string.IsNullOrWhiteSpace(surveyFor) && dt.Rows.Count > 0)
                {
                    GenerateRatingReportExcelFile(dt, surveyFor, includeRaters);
                }
            }
            return(RedirectToAction("PrintRatingReport"));
        }
        public IHttpActionResult PrintRatingReport(string Survey_For)
        {
            //surveyFor = "Andile Madiba";

            if (string.IsNullOrWhiteSpace(Survey_For))
            {
                return(Ok());
            }

            List <string> itemRow = new List <string>();

            RatingReport reportObject = new RatingReport();

            DataTable dt = new DataTable();

            SurveyForList surveyReportPParameterObject = new SurveyForList();

            surveyReportPParameterObject.Type = "Annually";

            surveyReportPParameterObject.Period = "2016";

            surveyReportPParameterObject.Survey_For = Survey_For;

            var raterList = new List <string>();

            if (!string.IsNullOrWhiteSpace(Survey_For))
            {
                var report = new Surveys().getSurveyForReport(surveyReportPParameterObject).GroupBy(c => c.Question_ID).Select(y => y.FirstOrDefault()).ToList();

                //dt = reportObject.GetColumns(dt, report);

                //reportObject.AddHeadings(dt, Survey_For, report.First().Period);

                //reportObject.AddQuestionHeadings(dt, report);

                //reportObject.AddQuestionAverallMinRating(dt, report);

                //reportObject.AddQuestionAverallMaxRating(dt, report);

                //reportObject.AddQuestionAverageRating(dt, report);

                //dt.Rows.Add(new List<string>().ToArray());

                //itemRow.Add("INDIVIDUAL RATER SCORES AND COMMENTS");

                //dt.Rows.Add(itemRow.ToArray());

                //foreach (var rater in report)
                //{
                //    if (!(raterList.Contains(rater.Rater)))
                //    {
                //        reportObject.AddIndividualRaterComment(dt, report);

                //        reportObject.AddIndividualRating(dt, report);

                //        raterList.Add(rater.Rater);
                //    }

                //}

                return(Ok(report));
            }

            //if (!string.IsNullOrWhiteSpace(Survey_For))
            //{
            //    GenerateRatingReportExcelFile(dt, Survey_For);
            //}
            return(Ok());
        }