Пример #1
0
        private void SaveEditSurvey(IDialogContext context, dynamic resultValue, EventEntity oneEventEntity)
        {
            // Get card from result
            Dictionary <string, string> editedQuestionList = resultValue.ToObject <Dictionary <string, string> >();

            for (int i = 0; i < questionList.Count; i++)
            {
                if (editedQuestionList.ContainsKey("q" + i))
                {
                    if (!(string.IsNullOrEmpty(editedQuestionList["q" + i]) || string.IsNullOrWhiteSpace(editedQuestionList["q" + i])))
                    {
                        questionList[i] = editedQuestionList["q" + i];
                    }
                }
            }

            //Serialize the object back and save it
            var survey   = new List <QuestionEntity>();
            var question = new QuestionEntity();

            for (int i = 0; i < questionList.Count; i++)
            {
                question = new QuestionEntity();
                question.PartitionKey = oneEventEntity.SurveyCode;
                question.RowKey       = (i + 1).ToString();
                question.AnswerList   = JsonConvert.SerializeObject(answerList[i]);
                question.QuestionText = questionList[i];
                survey.Add(question);
            }

            oneEventEntity.Survey = JsonConvert.SerializeObject(survey);

            var        storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
            var        tableClient    = storageAccount.CreateCloudTableClient();
            CloudTable cloudTable     = tableClient.GetTableReference("Event");

            cloudTable.CreateIfNotExists();
            cloudTable.Execute(TableOperation.InsertOrMerge(oneEventEntity));
        }
Пример #2
0
        private async Task ResumeAfterSurveyPrompt(IDialogContext context, IAwaitable <string> result)
        {
            var         message     = await result;
            EventEntity eventEntity = new EventEntity();

            if (message.Equals("-") && surveyList.Count == 0)
            {
                eventDetails.Add(GenerateCode());//15 - Survey Code

                var            survey     = new List <QuestionEntity>();
                QuestionEntity question   = new QuestionEntity();
                var            answerList = new List <string>();
                question = new QuestionEntity(eventDetails[15], "1");
                question.QuestionText = ("This survey has no question. Type anything to exit this survey.");
                question.AnswerList   = JsonConvert.SerializeObject(answerList);
                survey.Add(question);

                eventDetails.Add(JsonConvert.SerializeObject(survey));//16 - Survey

                var        storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
                var        tableClient    = storageAccount.CreateCloudTableClient();
                CloudTable eventTable     = tableClient.GetTableReference("Event");
                eventTable.CreateIfNotExists();

                eventDetails.Add(""); //17 - Attendance Code 1
                eventDetails.Add(""); //18 - Attendance Code 2
                eventDetails.Add(""); //19 - Day

                for (int i = 0; i < totalDays; i++)
                {
                    if (code1.Count != 0)
                    {
                        eventDetails[17] = code1[i];//Set Attendance Code 1
                    }
                    if (code2.Count != 0)
                    {
                        eventDetails[18] = code2[i];//Set Attendance Code 2
                    }
                    string code = "";
                    while (true)
                    {
                        code = Guid.NewGuid().ToString().Substring(0, 8);
                        TableOperation retrieveOperation = TableOperation.Retrieve <EventEntity>(context.UserData.GetValue <string>(ContextConstants.UserId), code);
                        TableResult    retrievedResult   = eventTable.Execute(retrieveOperation);

                        if (retrievedResult.Result == null)
                        {
                            break;
                        }
                    }

                    eventDetails[1]  = code;       //Reset Row Key
                    eventDetails[19] = i + 1 + ""; //Set Day

                    eventEntity                          = new EventEntity(eventDetails[0], eventDetails[1]);
                    eventEntity.EventName                = eventDetails[2];
                    eventEntity.EventStartDate           = eventDetails[3];
                    eventEntity.EventEndDate             = eventDetails[4];
                    eventEntity.AttendanceCode1StartTime = eventDetails[5];
                    eventEntity.AttendanceCode1EndTime   = eventDetails[6];
                    eventEntity.AttendanceCode2StartTime = eventDetails[7];
                    eventEntity.AttendanceCode2EndTime   = eventDetails[8];
                    eventEntity.SurveyEndDate            = eventDetails[9];
                    eventEntity.SurveyEndTime            = eventDetails[10];
                    eventEntity.Description              = eventDetails[11];
                    eventEntity.Anonymous                = eventDetails[12];
                    eventEntity.Email                    = eventDetails[13];
                    eventEntity.Password                 = eventDetails[14];
                    eventEntity.SurveyCode               = eventDetails[15];
                    eventEntity.Survey                   = eventDetails[16];
                    eventEntity.AttendanceCode1          = eventDetails[17];
                    eventEntity.AttendanceCode2          = eventDetails[18];
                    eventEntity.Day                      = eventDetails[19];
                    TableOperation insertOperation1 = TableOperation.InsertOrMerge(eventEntity);
                    eventTable.Execute(insertOperation1);
                }

                string eventMsg = "'" + eventEntity.EventName + "' has been created, with a total of " + survey.Count + " questions. \n\n";
                eventMsg += "Date: " + eventEntity.EventStartDate + " to " + eventEntity.EventEndDate + "\n\n";
                eventMsg += "Attendance Code 1: \n\n";
                for (int i = 0; i < code1.Count; i++)
                {
                    eventMsg += "Day " + (i + 1) + ": " + (code1[i] == null ? "-" : code1[i]) + "\n\n";
                }
                eventMsg += "\n\n" + "Attendance Code 2:  \n\n";
                for (int i = 0; i < code2.Count; i++)
                {
                    eventMsg += "Day " + (i + 1) + ": " + (code2[i] == null ? "-" : code2[i]) + "\n\n";
                }
                eventMsg += "\n\n" + "Survey Code: " + eventEntity.SurveyCode + "\n\n\n\n"
                            + "Type /Event to manage your event. Thank you and have a great day ahead!";

                await context.PostAsync(eventMsg);

                bool a = SharedFunction.EmailEvent(eventEntity, context.UserData.GetValue <string>(ContextConstants.Name), survey, code1, code2);
                context.Done(this);
            }
            else if (message.Equals("-"))
            {
                eventDetails.Add(GenerateCode());//15 - Survey Code

                var            survey   = new List <QuestionEntity>();
                QuestionEntity question = new QuestionEntity();

                for (int i = 0; i < surveyList.Count; i++)
                {
                    var answerList = new List <string>();
                    question = new QuestionEntity(eventDetails[15], (i + 1).ToString());
                    question.QuestionText = surveyList[i];
                    if (optionList[i] == 2)
                    {
                        answerList.Add("Yes");
                        answerList.Add("No");
                    }
                    else if (optionList[i] == 3)
                    {
                        answerList.Add("Too Long");
                        answerList.Add("Just Right");
                        answerList.Add("Too Short");
                    }
                    else if (optionList[i] == 4)
                    {
                        answerList.Add("Strongly Agree");
                        answerList.Add("Agree");
                        answerList.Add("Somewhat Agree");
                        answerList.Add("Neutral");
                        answerList.Add("Somewhat Disagree");
                        answerList.Add("Disagree");
                        answerList.Add("Strongly Disagree");
                        answerList.Add("NA");
                    }
                    else if (optionList[i] == 5)
                    {
                        answerList.Add("Strongly Satisfied");
                        answerList.Add("Satisfied");
                        answerList.Add("Somewhat Satisfied");
                        answerList.Add("Neutral");
                        answerList.Add("Somewhat Dissatisfied");
                        answerList.Add("Dissatisfied");
                        answerList.Add("Strongly Dissatisfied");
                        answerList.Add("NA");
                    }
                    else if (optionList[i] == 6)
                    {
                        answerList.Add("Highly Relevant");
                        answerList.Add("Relevant");
                        answerList.Add("Somewhat Relevant");
                        answerList.Add("Neutral");
                        answerList.Add("Somewhat Irrelevant");
                        answerList.Add("Irrelevant");
                        answerList.Add("Highly Irrelevant");
                        answerList.Add("NA");
                    }
                    //Retrieving the answer list

                    question.AnswerList = JsonConvert.SerializeObject(answerList);
                    survey.Add(question);
                }
                eventDetails.Add(JsonConvert.SerializeObject(survey));//16 - Survey

                var        storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
                var        tableClient    = storageAccount.CreateCloudTableClient();
                CloudTable eventTable     = tableClient.GetTableReference("Event");
                eventTable.CreateIfNotExists();
                eventDetails.Add(""); //17 - Attendance Code 1
                eventDetails.Add(""); //18 - Attendance Code 2
                eventDetails.Add(""); //19 - Day

                for (int i = 0; i < totalDays; i++)
                {
                    if (code1.Count != 0)
                    {
                        eventDetails[17] = code1[i];//Set Attendance Code 1
                    }
                    if (code2.Count != 0)
                    {
                        eventDetails[18] = code2[i];//Set Attendance Code 2
                    }
                    string code = "";
                    while (true)
                    {
                        code = Guid.NewGuid().ToString().Substring(0, 8);
                        TableOperation retrieveOperation = TableOperation.Retrieve <EventEntity>(context.UserData.GetValue <string>(ContextConstants.UserId), code);
                        TableResult    retrievedResult   = eventTable.Execute(retrieveOperation);

                        if (retrievedResult.Result == null)
                        {
                            break;
                        }
                    }
                    eventDetails[1]                      = code;       //Reset Row Key
                    eventDetails[19]                     = i + 1 + ""; //Set Day
                    eventEntity                          = new EventEntity(eventDetails[0], eventDetails[1]);
                    eventEntity.EventName                = eventDetails[2];
                    eventEntity.EventStartDate           = eventDetails[3];
                    eventEntity.EventEndDate             = eventDetails[4];
                    eventEntity.AttendanceCode1StartTime = eventDetails[5];
                    eventEntity.AttendanceCode1EndTime   = eventDetails[6];
                    eventEntity.AttendanceCode2StartTime = eventDetails[7];
                    eventEntity.AttendanceCode2EndTime   = eventDetails[8];
                    eventEntity.SurveyEndDate            = eventDetails[9];
                    eventEntity.SurveyEndTime            = eventDetails[10];
                    eventEntity.Description              = eventDetails[11];
                    eventEntity.Anonymous                = eventDetails[12];
                    eventEntity.Email                    = eventDetails[13];
                    eventEntity.Password                 = eventDetails[14];
                    eventEntity.SurveyCode               = eventDetails[15];
                    eventEntity.Survey                   = eventDetails[16];
                    eventEntity.AttendanceCode1          = eventDetails[17];
                    eventEntity.AttendanceCode2          = eventDetails[18];
                    eventEntity.Day                      = eventDetails[19];
                    TableOperation insertOperation1 = TableOperation.InsertOrMerge(eventEntity);
                    eventTable.Execute(insertOperation1);
                }

                string eventMsg = "'" + eventEntity.EventName + "' has been created, with a total of " + survey.Count + " questions. \n\n";
                eventMsg += "Date: " + eventEntity.EventStartDate + " to " + eventEntity.EventEndDate + "\n\n";
                eventMsg += "Attendance Code 1: \n\n";
                for (int i = 0; i < code1.Count; i++)
                {
                    eventMsg += "Day " + (i + 1) + ": " + (code1[i] == null ? "-" : code1[i]) + "\n\n";
                }
                eventMsg += "\n\n" + "Attendance Code 2:  \n\n";
                for (int i = 0; i < code2.Count; i++)
                {
                    eventMsg += "Day " + (i + 1) + ": " + (code2[i] == null ? "-" : code2[i]) + "\n\n";
                }
                eventMsg += "\n\n" + "Survey Code: " + eventEntity.SurveyCode + "\n\n\n\n"
                            + "Type /Event to manage your event. Thank you and have a great day ahead!";

                await context.PostAsync(eventMsg);

                bool a = SharedFunction.EmailEvent(eventEntity, context.UserData.GetValue <string>(ContextConstants.Name), survey, code1, code2);
                context.Done(this);
            }
            else
            {
                surveyList.Add(message);
                string promptText = "";

                promptText  = "For survey question " + qCount + ", what are the options?";
                promptText += "\n1. Open Ended Question(Users can freely answer)";
                promptText += "\n2. Yes|No";
                promptText += "\n3. Too Long|Just Right|Too Short";
                promptText += "\n4. Strongly Agree|...|Neutral|...|Strongly Disagree|NA(Total 8 choices)";
                promptText += "\n5. Strongly Satisfied|...|Neutral|...|Strongly Dissatisfied|NA(Total 8 choices)";
                promptText += "\n6. Highly Relevant|...|Neutral|...|Highly Irrelevant|NA(Total 8 choices)";
                PromptDialog.Number(context, this.ResumeAfterOptionsPrompt, promptText, promptText, 100, null, 1, 6);
            }
        }
Пример #3
0
        private async Task ResumeAfterPrompt(IDialogContext context, IAwaitable <IEnumerable <Attachment> > result)
        {
            context.UserData.SetValue(ContextConstants.UserId, context.Activity.From.Id);
            try
            {
                //Connecting to storage
                var        storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
                var        tableClient    = storageAccount.CreateCloudTableClient();
                CloudTable eventTable     = tableClient.GetTableReference("Event");
                eventTable.CreateIfNotExists();

                //Get the Attachment
                var message = await result;
                var msg     = context.MakeMessage();
                msg.Type = ActivityTypes.Typing;
                await context.PostAsync(msg);

                var excelName = "";

                string          destinationContainer = "surveytemplates";
                CloudBlobClient blobClient           = storageAccount.CreateCloudBlobClient();
                var             blobContainer        = blobClient.GetContainerReference(destinationContainer);
                blobContainer.CreateIfNotExists();
                String newFileName = "";

                //Receiving the attachment
                foreach (Attachment a in message)
                {
                    try
                    {
                        excelName = a.Name;

                        using (HttpClient httpClient = new HttpClient())
                        {
                            var responseMessage = await httpClient.GetAsync(a.ContentUrl);

                            var contentLenghtBytes = responseMessage.Content.Headers.ContentLength;
                            var fileByte           = await httpClient.GetByteArrayAsync(a.ContentUrl);

                            //Set file name
                            newFileName = context.UserData.GetValue <string>(ContextConstants.UserId) + "_" + DateTime.Now.ToString("MMddyyyy-hhmmss") + "_" + excelName;

                            string sourceUrl = a.ContentUrl;

                            // Set the permissions so the blobs are public. //ON HOLD
                            BlobContainerPermissions permissions = new BlobContainerPermissions
                            {
                                PublicAccess = BlobContainerPublicAccessType.Blob
                            };
                            blobContainer.SetPermissions(permissions);

                            var newBlockBlob = blobContainer.GetBlockBlobReference(newFileName);

                            try
                            {
                                using (var memoryStream = new System.IO.MemoryStream(fileByte))
                                {
                                    newBlockBlob.UploadFromStream(memoryStream);
                                    newBlockBlob.Properties.ContentType = a.ContentType;
                                }
                                newBlockBlob.SetProperties();
                            }
                            catch (Exception ex)
                            {
                                await context.PostAsync("Something went wrong with uploading, please type \'/ce\' to try again.");

                                context.Done(this);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        await context.PostAsync("Something went wrong with uploading, please type \'/ce\' to try again.");

                        context.Done(this);
                    }
                }
                try
                {
                    //Opening the Excel File
                    CloudBlockBlob blob = blobContainer.GetBlockBlobReference(newFileName);

                    //Check for unique entity
                    DateTime thisDay = DateTime.Today;
                    String   today   = FormatDate(thisDay.ToString("d"));

                    var eventCode = GenerateCode();

                    //After checking that there are no duplicates in generated codes
                    EventEntity eventEntity = new EventEntity(context.UserData.GetValue <string>(ContextConstants.UserId), eventCode);

                    using (HttpClient httpClient = new HttpClient())
                    {
                        var fileByte = await httpClient.GetByteArrayAsync(blob.Uri.ToString());

                        try
                        {
                            XSSFWorkbook wb;
                            XSSFSheet    sh;

                            using (var memoryStream = new MemoryStream(fileByte))
                            {
                                wb = new XSSFWorkbook(memoryStream);
                            }

                            sh = (XSSFSheet)wb.GetSheetAt(0);

                            //Check event start date and event name
                            if (sh.GetRow(2).GetCell(1) != null && sh.GetRow(2).GetCell(1).ToString() != "" && sh.GetRow(1).GetCell(1) != null && sh.GetRow(1).GetCell(1).ToString() != "")
                            {
                                //DateTime dateTime;
                                DataFormatter dataFormatter = new DataFormatter();
                                var           date          = dataFormatter.FormatCellValue(sh.GetRow(2).GetCell(1));
                                int           totalDays     = 1;
                                var           error         = false;

                                DateTime sDate;
                                DateTime eDate;

                                //Try to parse date in the specified format
                                if (ParseDate(date, thisDay))
                                {
                                    String[] split = date.Split(new Char[] { '/', '-' });
                                    date = split[0].ToString() + '/' + split[1].ToString() + '/' + split[2];
                                    eventEntity.EventStartDate = date;
                                    DateTime.TryParseExact(dataFormatter.FormatCellValue(sh.GetRow(2).GetCell(1)), new string[] { "dd/MM/yyyy", "dd-MM-yyyy" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out sDate);

                                    //Check Event End Date
                                    if (sh.GetRow(3).GetCell(1) != null && sh.GetRow(3).GetCell(1).ToString() != "")
                                    {
                                        date = dataFormatter.FormatCellValue(sh.GetRow(3).GetCell(1));
                                        if (ParseDate(date, sDate))
                                        {
                                            split = date.Split(new Char[] { '/', '-' });
                                            date  = split[0].ToString() + '/' + split[1].ToString() + '/' + split[2];
                                            eventEntity.EventEndDate = date;
                                            DateTime.TryParseExact(dataFormatter.FormatCellValue(sh.GetRow(3).GetCell(1)), new string[] { "dd/MM/yyyy", "dd-MM-yyyy" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out eDate);
                                            totalDays = (eDate - sDate).Days + 1;
                                            if (totalDays > 31)
                                            {
                                                error = true;
                                                await context.PostAsync("Sorry, we currently do not support events that have more than 31 days.");

                                                await context.PostAsync(msg);

                                                await context.PostAsync("Talk to me again if you require my assistance.");

                                                context.Done(this);
                                            }
                                        }
                                        else
                                        {
                                            error = true;
                                            await context.PostAsync("Please check your excel file and input an end date in the format specified(dd-mm-yyyy or dd/mm/yyyy) and not before today's date!");

                                            await context.PostAsync(msg);

                                            await context.PostAsync("Talk to me again if you require my assistance.");

                                            context.Done(this);
                                        }
                                    }
                                    else
                                    {
                                        eventEntity.EventEndDate = eventEntity.EventStartDate;
                                    }
                                    //End of Checking Event's End Date

                                    //Check Attendance Code 1 Time
                                    var startTime = dataFormatter.FormatCellValue(sh.GetRow(4).GetCell(1));
                                    var endTime   = dataFormatter.FormatCellValue(sh.GetRow(5).GetCell(1));

                                    var code1 = new List <string>();
                                    var code2 = new List <string>();

                                    if (sh.GetRow(4).GetCell(1) != null && sh.GetRow(4).GetCell(1).ToString() != "" && sh.GetRow(5).GetCell(1) != null && sh.GetRow(5).GetCell(1).ToString() != "")
                                    {
                                        if (ParseTime(startTime, endTime))
                                        {
                                            eventEntity.AttendanceCode1StartTime = startTime;
                                            eventEntity.AttendanceCode1EndTime   = endTime;

                                            for (int i = 0; i < totalDays; i++)
                                            {
                                                //Generate unique attendanceCode1
                                                code1.Add(GenerateCode());
                                            }
                                        }
                                        else
                                        {
                                            error = true;
                                            await context.PostAsync("Please check your excel file and valid Attendance Code 1 Start/End Time in the format specified(2359). The end time should not be before the start time.");

                                            await context.PostAsync(msg);

                                            await context.PostAsync("Talk to me again if you require my assistance.");

                                            context.Done(this);
                                        }
                                    }
                                    else if (sh.GetRow(4).GetCell(1).ToString() == "" && sh.GetRow(5).GetCell(1).ToString() == "")
                                    {
                                        eventEntity.AttendanceCode1StartTime = "";
                                        eventEntity.AttendanceCode1EndTime   = "";
                                    }
                                    else
                                    {
                                        error = true;
                                        await context.PostAsync("Please check your excel file and valid Attendance Code 1 Start/End Time in the format specified(2359). The end time should not be before the start time.");

                                        await context.PostAsync(msg);

                                        await context.PostAsync("Talk to me again if you require my assistance.");

                                        context.Done(this);
                                    }
                                    //End of Attendance Code 1 Time

                                    //Check Attendance Code 2 Time
                                    startTime = dataFormatter.FormatCellValue(sh.GetRow(6).GetCell(1));
                                    endTime   = dataFormatter.FormatCellValue(sh.GetRow(7).GetCell(1));
                                    if (sh.GetRow(6).GetCell(1) != null && sh.GetRow(6).GetCell(1).ToString() != "" && sh.GetRow(7).GetCell(1) != null && sh.GetRow(7).GetCell(1).ToString() != "")
                                    {
                                        if (ParseTime(startTime, endTime))
                                        {
                                            eventEntity.AttendanceCode2StartTime = startTime;
                                            eventEntity.AttendanceCode2EndTime   = endTime;

                                            for (int i = 0; i < totalDays; i++)
                                            {
                                                //Generate unique attendanceCode2
                                                code2.Add(GenerateCode());
                                            }
                                        }
                                        else
                                        {
                                            error = true;
                                            await context.PostAsync("Please check your excel file and valid Attendance Code 2 Start/End Time in the format specified(2359). The end time should not be before the start time.");

                                            await context.PostAsync(msg);

                                            await context.PostAsync("Talk to me again if you require my assistance.");

                                            context.Done(this);
                                        }
                                    }
                                    else
                                    {
                                        eventEntity.AttendanceCode2StartTime = "";
                                        eventEntity.AttendanceCode2EndTime   = "";
                                    }
                                    //End of Attendance Code 2 Time

                                    //Check Survey End Date
                                    if (sh.GetRow(8).GetCell(1) != null && sh.GetRow(8).GetCell(1).ToString() != "")
                                    {
                                        date = dataFormatter.FormatCellValue(sh.GetRow(8).GetCell(1));
                                        if (ParseDate(date, sDate))
                                        {
                                            split = date.Split(new Char[] { '/', '-' });
                                            date  = split[0] + '/' + split[1] + '/' + split[2];
                                            eventEntity.SurveyEndDate = date;
                                        }
                                        else//Input date is not in the specified format
                                        {
                                            error = true;
                                            await context.PostAsync("Please check your excel file and input a Survey End Date in the format specified(dd-mm-yyyy or dd/mm/yyyy) and not before today's date!");

                                            await context.PostAsync(msg);

                                            await context.PostAsync("Talk to me again if you require my assistance.");

                                            context.Done(this);
                                        }
                                    }
                                    else
                                    {
                                        if (eventEntity.EventEndDate != "")
                                        {
                                            eventEntity.SurveyEndDate = eventEntity.EventEndDate;
                                        }
                                        else
                                        {
                                            eventEntity.SurveyEndDate = eventEntity.EventStartDate;
                                        }
                                    }
                                    //End of checking Survey End Date

                                    //Check Survey End Time
                                    endTime = dataFormatter.FormatCellValue(sh.GetRow(9).GetCell(1));
                                    if (sh.GetRow(9).GetCell(1) != null && sh.GetRow(9).GetCell(1).ToString() != "")
                                    {
                                        if (ParseTime("0000", endTime))
                                        {
                                            eventEntity.SurveyEndTime = endTime;
                                        }
                                        else
                                        {
                                            error = true;
                                            await context.PostAsync("Please check your excel file and your Survey End Time in the format specified(2359).");

                                            await context.PostAsync(msg);

                                            await context.PostAsync("Talk to me again if you require my assistance.");

                                            context.Done(this);
                                        }
                                    }
                                    else
                                    {
                                        eventEntity.SurveyEndTime = "2359";
                                    }
                                    //End of Attendance Code 2 Time

                                    //Start of Anonymity
                                    if (sh.GetRow(11).GetCell(1) != null && sh.GetRow(11).GetCell(1).ToString() != "" && (sh.GetRow(11).GetCell(1).ToString() == "Y" || sh.GetRow(11).GetCell(1).ToString() == "N" || sh.GetRow(11).GetCell(1).ToString() == "Yes" || sh.GetRow(11).GetCell(1).ToString() == "No"))
                                    {
                                        eventEntity.Anonymous = (sh.GetRow(11).GetCell(1).ToString());
                                    }
                                    else
                                    {
                                        error = true;
                                        await context.PostAsync("Please check your excel file and input either Y or N for Anonymity.");

                                        await context.PostAsync(msg);

                                        await context.PostAsync("Talk to me again if you require my assistance.");

                                        context.Done(this);
                                    }
                                    //End of Anonymity

                                    //Start of Email
                                    if (sh.GetRow(12).GetCell(1) != null && sh.GetRow(12).GetCell(1).ToString() != "")
                                    {
                                        try
                                        {
                                            System.Net.Mail.MailAddress mail = new System.Net.Mail.MailAddress(sh.GetRow(12).GetCell(1).ToString());

                                            eventEntity.Email = (sh.GetRow(12).GetCell(1).ToString());
                                        }
                                        catch (FormatException)
                                        {
                                            error = true;
                                            await context.PostAsync("Please check your excel file and input a valid Email address or remove the field.");

                                            await context.PostAsync(msg);

                                            await context.PostAsync("Talk to me again if you require my assistance.");

                                            context.Done(this);
                                        }
                                    }
                                    else
                                    {
                                        eventEntity.Email = "";
                                    }
                                    //End of Email

                                    //If the file got no error parsing all the values
                                    if (!error)
                                    {
                                        //Setting eventEntity variables
                                        eventEntity.Description = dataFormatter.FormatCellValue(sh.GetRow(10).GetCell(1));
                                        eventEntity.EventName   = (sh.GetRow(1).GetCell(1).ToString());

                                        if (sh.GetRow(13).GetCell(1).ToString() != "")
                                        {
                                            eventEntity.Password = Sha256(sh.GetRow(13).GetCell(1).ToString());
                                        }
                                        else
                                        {
                                            eventEntity.Password = "";
                                        }

                                        var            survey   = new List <QuestionEntity>();
                                        QuestionEntity question = new QuestionEntity();
                                        eventEntity.SurveyCode = GenerateCode();

                                        //retrieving the questions
                                        for (int i = 35; i <= sh.LastRowNum; i++)
                                        {
                                            var answerList = new List <string>();

                                            if (sh.GetRow(i).GetCell(0) != null && sh.GetRow(i).GetCell(0).ToString() != "")
                                            {
                                                int x = 1;
                                                question = new QuestionEntity(eventEntity.SurveyCode, (i - 34).ToString());
                                                question.QuestionText = (sh.GetRow(i).GetCell(0).ToString());

                                                //Retrieving the answer list
                                                while (sh.GetRow(i).GetCell(x) != null && sh.GetRow(i).GetCell(x).ToString() != "")
                                                {
                                                    answerList.Add(sh.GetRow(i).GetCell(x).ToString());
                                                    x++;
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                            question.AnswerList = JsonConvert.SerializeObject(answerList);
                                            survey.Add(question);
                                        }
                                        //No question is found in excel file
                                        if (survey.Count == 0)
                                        {
                                            await context.PostAsync("Your excel file does not contain any question, please check again! (Read the guidelines in the provided template)");

                                            await context.PostAsync(msg);

                                            await context.PostAsync("Talk to me again if you require my assistance.");

                                            context.Done(this);
                                        }
                                        else//Questions were found in excel file, process inserting of event
                                        {
                                            eventEntity.Survey = JsonConvert.SerializeObject(survey);
                                            for (int i = 0; i < totalDays; i++)
                                            {
                                                if (code1.Count != 0)
                                                {
                                                    eventEntity.AttendanceCode1 = code1[i];
                                                }
                                                if (code2.Count != 0)
                                                {
                                                    eventEntity.AttendanceCode2 = code2[i];
                                                }
                                                string code = "";
                                                while (true)
                                                {
                                                    code = Guid.NewGuid().ToString().Substring(0, 8);
                                                    TableOperation retrieveOperation = TableOperation.Retrieve <EventEntity>(context.UserData.GetValue <string>(ContextConstants.UserId), code);
                                                    TableResult    retrievedResult   = eventTable.Execute(retrieveOperation);

                                                    if (retrievedResult.Result == null)
                                                    {
                                                        break;
                                                    }
                                                }
                                                eventEntity.RowKey = code;
                                                eventEntity.Day    = (i + 1).ToString();
                                                TableOperation insertOperation1 = TableOperation.InsertOrMerge(eventEntity);
                                                eventTable.Execute(insertOperation1);
                                            }

                                            await context.PostAsync(msg);

                                            string eventMsg = "'" + eventEntity.EventName + "' has been created, with a total of " + survey.Count + " questions. \n\n";
                                            eventMsg += "Date: " + eventEntity.EventStartDate + " to " + eventEntity.EventEndDate + "\n\n";
                                            eventMsg += "Attendance Code 1: \n\n";
                                            for (int i = 0; i < code1.Count; i++)
                                            {
                                                eventMsg += "Day " + (i + 1) + ": " + (code1[i] == null ? "-" : code1[i]) + "\n\n";
                                            }
                                            eventMsg += "\n\n" + "Attendance Code 2:  \n\n";
                                            for (int i = 0; i < code2.Count; i++)
                                            {
                                                eventMsg += "Day " + (i + 1) + ": " + (code2[i] == null ? "-" : code2[i]) + "\n\n";
                                            }
                                            eventMsg += "\n\n" + "Survey Code: " + eventEntity.SurveyCode + "\n\n\n\n"
                                                        + "Type /Event to manage your event. Thank you and have a great day ahead!";

                                            await context.PostAsync(eventMsg);

                                            bool a = SharedFunction.EmailEvent(eventEntity, context.UserData.GetValue <string>(ContextConstants.Name), survey, code1, code2);
                                            context.Done(this);
                                        }
                                    }
                                }
                                else//Input date is not in the specified format
                                {
                                    await context.PostAsync("Please check your excel file and input a date in the format specified(dd-mm-yyyy or dd/mm/yyyy) and not before today's date!");

                                    await context.PostAsync(msg);

                                    await context.PostAsync("Talk to me again if you require my assistance.");

                                    context.Done(this);
                                }
                            }
                            else
                            {
                                await context.PostAsync("Please check your excel file to see if you have inputted an Event Name and Event Start Date!");

                                await context.PostAsync(msg);

                                await context.PostAsync("Talk to me again if you require my assistance.");

                                context.Done(this);
                            }
                        }
                        catch (Exception ex)
                        {
                            await context.PostAsync("Sorry there is an error trying to open your file, please type \'/ce\' to try again.");

                            context.Done(this);
                        }
                    }
                }
                catch (Exception e) {
                    await context.PostAsync("Sorry there is an error trying to open your file, please type \'/ce\' to try again.");

                    context.Done(this);
                }
            }
            catch (TooManyAttemptsException e)
            {
            }
        }