コード例 #1
0
        public ActionResult UploadEmployeeSurvey(HttpPostedFileBase fileUploadClientFile)
        {
            var saveClientFile = string.Empty;

            var questionObject = new QuestionnaireObject();

            GetEmployeeInformation();

            //First Check if the uploaded file is not null
            if (fileUploadClientFile != null && fileUploadClientFile.ContentLength > 0)
            {
                //Save uploaded file in the survey temp folder - under App_Data
                var uploadStatus = SaveFile(fileUploadClientFile);

                questionObject.UploadStatus = uploadStatus;
            }


            if (string.IsNullOrWhiteSpace(saveClientFile))
            {
                return(View(questionObject));
            }

            return(View(questionObject));
        }
コード例 #2
0
        public ActionResult SaveQuestion(QuestionnaireObject questionObject)
        {
            var list = new List <QuestionnaireObject>();

            //Reading a list of questions that catched by the application
            var tempList = System.Web.Helpers.WebCache.Get("QuestionsEntered");

            var ratersObjectList = new List <Rater>();

            var questionObj = new QuestionnaireObject();

            questionObj.Question = questionObject.Question;

            var ratersList = questionObject.RateeName.Split(',');

            //Looping through a list of raters
            foreach (var item in ratersList)
            {
                ratersObjectList.Add(new Rater()
                {
                    Name = item
                });
            }

            questionObj.Raters = questionObject.Raters;

            questionObj.KPIDesc = questionObject.KPIDesc;

            // if (tempList != null) { list.Add(tempList); }

            list.Add(new QuestionnaireObject()
            {
                Question = questionObj.Question, KPIDesc = questionObj.KPIDesc, Raters = ratersObjectList, RatersString = questionObject.RateeName
            });

            if (tempList == null)
            {
                System.Web.Helpers.WebCache.Set("QuestionsEntered", list);
            }


            var data = JsonConvert.SerializeObject(list);

            return(Json(data));
        }
コード例 #3
0
        public IHttpActionResult SaveQuestion(QuestionnaireObject questionObject)
        {
            var list = new List <QuestionnaireObject>();

            tempList = System.Web.Helpers.WebCache.Get("QuestionsEntered") != null?System.Web.Helpers.WebCache.Get("QuestionsEntered") : new List <QuestionnaireObject>();

            var questionObj = new QuestionnaireObject();

            var ratersObjectList = new List <Rater>();

            questionObj.Question = questionObject.Question;

            questionObj.Raters = questionObject.Raters;

            questionObj.KPIDesc = questionObject.KPIDesc;

            if (tempList.Where(c => c.Question == questionObject.Question).Count() > 0)
            {
                return(Conflict());
            }

            // if (tempList != null) { list.Add(tempList); }

            //Convert comma separated list of raters into an array
            var ratersList = questionObject.RatersString.Split(',');

            if (questionObject.QuestionnairePeriodType == "Monthly")
            {
                questionObject.QuestionnairePeriodValue = int.Parse(questionObject.QuestionnairePeriodValue) < 10 ? (DateTime.Now.Year.ToString() + "0" + questionObject.QuestionnairePeriodValue) : (DateTime.Now.Year.ToString() + questionObject.QuestionnairePeriodValue);
            }
            else if (questionObject.QuestionnairePeriodType == "Quartely")
            {
                questionObject.QuestionnairePeriodValue = DateTime.Now.Year.ToString() + "0" + questionObject.QuestionnairePeriodValue;
            }
            else if (questionObject.QuestionnairePeriodType == "Annually")
            {
                questionObject.QuestionnairePeriodValue = questionObject.QuestionnairePeriodValue;
            }

            foreach (var item in ratersList)
            {
                ratersObjectList.Add(new Rater()
                {
                    Name = item
                });
            }

            list.Add(new QuestionnaireObject()
            {
                Question = questionObj.Question, KPIDesc = questionObj.KPIDesc, Raters = ratersObjectList
            });

            //Save to the database
            tempList.Add(new QuestionnaireObject()
            {
                Question = questionObj.Question, KPIDesc = questionObj.KPIDesc, Raters = questionObj.Raters, RatersString = questionObject.RatersString
            });

            System.Web.Helpers.WebCache.Set("QuestionsEntered", tempList);

            if (tempList == null)
            {
                System.Web.Helpers.WebCache.Set("QuestionsEntered", list);
            }

            //var data = JsonConvert.SerializeObject(tempList);

            return(Ok(tempList));
        }
コード例 #4
0
        public IHttpActionResult UploadFile()
        {
            //Get current loggedin user name from AD
            var userName = Generic.GetCurrentLogonUserName();

            var questionnaireObject = new QuestionnaireObject();

            var surveyList = new List <QuestionnaireObject>();

            var questionPreviewList = new List <QuestionnaireObject>();

            //Ensure that uploaded file has content otherwise exit the method
            if (HttpContext.Current.Request.Files.AllKeys.Any())
            {
                // Get uploaded file
                var postedFile = HttpContext.Current.Request.Files["UploadedFile"];

                if (postedFile.ContentLength > 0)
                {
                    //get file extension from the uploaded excel file
                    var fileExtension = Path.GetExtension(postedFile.FileName);

                    //Create a unique file name from a username, date, minutes and seconds
                    var fileName = Path.GetFileNameWithoutExtension(postedFile.FileName) + "_" + userName + "_" + DateTime.Now + DateTime.Now.Minute + DateTime.Now.Second + fileExtension;

                    //Remove unneccessary special characters from a file name
                    fileName = fileName.Replace(" ", "").Replace(":", "").Replace("AM", "").Replace("/", "").Replace("PM", "");

                    //Get file upload file path from a web config
                    var path = Path.Combine(HttpContext.Current.Server.MapPath(Config.FileUploadPath), fileName);

                    //Save uploaded file into the uploads folder - found unser App_Data
                    postedFile.SaveAs(path);

                    try
                    {
                        surveyList = ExcelFileUploadHelper.ProcessFileUpload(path, fileExtension, "", "");
                    }
                    catch (Exception ex)
                    {
                        MailMessage mail = new MailMessage();

                        SmtpClient SmtpServer = new SmtpClient("fgnotes.futuregrowth.co.za");

                        mail.From = new MailAddress("*****@*****.**");

                        mail.To.Add("*****@*****.**");

                        mail.Subject = "HR Performance System - Complete Survey Request Notification";

                        mail.Body = ex.Message + "User: "******", ", item.Raters.ConvertAll(r => string.Format("'{0}'", r.Name)).ToArray());

                        raters = raters.ToString().Replace("'", "");

                        //Adding questions and raters to questionPreviewList
                        questionPreviewList.Add(new QuestionnaireObject()
                        {
                            Question = item.Question, RateeName = raters
                        });
                    }
                }
            }
            //Serialize the list
            var data = JsonConvert.SerializeObject(questionPreviewList);

            return(Ok(data));
        }
コード例 #5
0
        //Saving a spreadsheet file to a directory
        public string SaveFile(HttpPostedFileBase postedFile)
        {
            var bulkInsert = 0;

            var uploadxml = new PADLL.Mviews.SurveyView.Uploadxml();

            uploadxml.Type = "Questionnaire";

            uploadxml.User = Generic.GetCurrentLogonUserName();

            var surveyObject = new PADLL.Create.xmlLoad();

            var userName = Generic.GetCurrentLogonUserName();

            //Get the name of an employee from a form control

            //Get a selected survey period (Annual, Quarter and Month) from a hidden input control - the hidden file is set in javaScript and stored in hidden input control
            var questionnairePeriodType = Request["QuestionnairePeriodType"];

            //Get a selected survey period value (for example 201603 if it is a quartely survey) from a hidden input control - the hidden file is set in javaScript and stored in hidden input control
            var questionnairePeriodValue = Request["QuestionnairePeriodValue"];

            var questionObject = new QuestionnaireObject();

            //remove special characters from a questionnaire value
            questionnairePeriodValue = questionnairePeriodValue.Trim(',');

            try
            {
                //Ensure that uploaded file is not null
                if (postedFile.ContentLength > 0)
                {
                    var fileExtension = Path.GetExtension(postedFile.FileName);

                    //Creating a file name from loggedin username, date, time, minutes and seconds to ensure that it's unique
                    var fileName = Path.GetFileNameWithoutExtension(postedFile.FileName) + "_" + userName + "_" + DateTime.Now + DateTime.Now.Minute + DateTime.Now.Second + fileExtension;

                    //Removing uneccessary special characters from a file name
                    fileName = fileName.Replace(" ", "").Replace(":", "").Replace("AM", "").Replace("/", "").Replace("PM", "");

                    //get a file path from an uploaded file
                    var path = Path.Combine(Server.MapPath(Config.FileUploadPath), fileName);

                    postedFile.SaveAs(path);

                    //Process the file and return a loist of questions including the business unit
                    var surveyList = ExcelFileUploadHelper.ProcessFileUpload(path, fileExtension, questionnairePeriodType, questionnairePeriodValue);

                    uploadxml.Filexml = XMLHelper.Serialize(surveyList);

                    //Return uploaded file status
                    if (surveyList.Count() > 0 && !string.IsNullOrWhiteSpace(userName))
                    {
                        bulkInsert = surveyObject.xmlUpload(uploadxml);

                        if (bulkInsert > 0)
                        {
                            questionObject.UploadStatus = "success";
                        }
                        else
                        {
                            questionObject.UploadStatus = "failed";
                        }
                        //var bulkInsert = SurveyTask.SaveClientBulkInsert(username, clientList);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            return(questionObject.UploadStatus);
        }