public async Task <ActionResult> GetAllBookMarks(string token)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           data             = await attendesBusiness.GetBookMarksByAttendeId(CurrentUserSession.AttendesID.Value);

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        // Duplicate code need to change
        public async Task <ActionResult> GetAttendeeProfilePic(int attendeeID)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           attendee         = await attendesBusiness.GetAttendesById(attendeeID);

            return(Json(compressedImageConvertionHandler(attendee.Thumbnail), JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> GetAttendeeEvents(string Token)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           data             = await attendesBusiness.GetAttendeEvents(CurrentUserSession.AttendesID.Value);

            return(Json(new { data = data }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> AttendeById(string Token, int id)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           x = await attendesBusiness.GetAttendesById(id);

            return(Json(new
            {
                data = new
                {
                    x.AddedON,
                    Bio = x.Description,
                    x.Email,
                    x.FirstName,
                    x.Lastname,
                    x.TitleName,
                    x.CompanyName,
                    x.Website,
                    x.InstagramURL,
                    x.LinkedinURL,
                    Thumbnail = imageToUrlConvertionHandler(x.Thumbnail),  // Helpers.ImageToBase64(MvcCustom.APiImagePath(x.Thumbnail)),
                    x.TwitterURL,
                    x.Status,
                    x.FacebookURL,
                    x.EnableMessaging,
                    x.EnableAlertEmails,
                    x.EnableAttendeeMessagingEmails,
                }
            }, JsonRequestBehavior.AllowGet));
        }
        public async Task <string> RemovePicture(string token, int id)
        {
            AttendesLogic attendesLogic = new AttendesLogic();
            string        filename      = await attendesLogic.GenerateAttendeeImageFromName(id, ImageSavePath, false);

            return(imageToUrlConvertionHandler(filename));
            //Helpers.ImageToBase64(MvcCustom.APiImagePath(filename));
        }
        public async Task <ActionResult> BookmarkActivity(string token, int activityId)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            await attendesBusiness.BookMarkActivity(CurrentUserSession.AttendesID.Value, activityId);

            await eventLogic.SaveLogs(CurrentUserSession.AttendesID.Value, "Bookmarking Activity", "Bookmarking Activity", "Activity has been bookmarked successfully");

            return(Json(new { data = new { Message = "Success" } }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> ChangeProfilePicture(string token, int id)
        {
            AttendesLogic attendesLogic = new AttendesLogic();
            var           uniquename    = Guid.NewGuid();
            string        name          = uniquename + ".png";
            await attendesLogic.ChangeProfilePicture(id, ImageSavePath, name);

            return(Json(new { Data = "Success" }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// Saves preferences for loggedin attendee
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="EnableMessaging"></param>
        /// <param name="EnableAlertEmails"></param>
        /// <param name="EnableAttendeeMessagingEmails"></param>
        /// <returns>Returns saved preferences data</returns>
        public async Task <ActionResult> SavePreferences(String Token, bool EnableMessaging = false, bool EnableAlertEmails = false, bool EnableAttendeeMessagingEmails = false)
        {
            AttendesLogic attendesLogic = new AttendesLogic();
            var           data          = await attendesLogic.SavePreferences(CurrentUserSession.AttendesID.Value, EnableMessaging, EnableAlertEmails, EnableAttendeeMessagingEmails);

            await eventLogic.SaveLogs(CurrentUserSession.AttendesID.Value, "Preferences", "Changing Preferences", "Preferences has been changed successfully");

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// preferences for loggedin attendee
        /// </summary>
        /// <param name="Token"></param>
        /// <returns> returns preferences data </returns>
        public async Task <ActionResult> GetPreferences(String Token)
        {
            AttendesLogic attendesLogic = new AttendesLogic();
            var           data          = await attendesLogic.GetPreferences(CurrentUserSession.AttendesID.Value);

            return(Json(data.Select(x => new Preferences
            {
                AttendeeID = x.ID,
                EnableMessaging = x.EnableMessaging,
                EnableAlertEmails = x.EnableAlertEmails,
                EnableAttendeeMessagingEmails = x.EnableAttendeeMessagingEmails
            }), JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> UpdateUserProfile(string token, DataAccess.DataBase.Model.Attende attende)
        {
            //attende.ID = CurrentUserSession.AttendesID.Value;
            AttendesLogic attendesBusiness = new AttendesLogic();

            //await ChangePhotos(token, Base64Image);
            await ChangeProfilePicture(token, attende.ID);

            attende.IsAdmin = IsAdmin;
            attendesBusiness.UpdateUserProfile(attende, CurrentUserSession.AttendesID.Value, ImageSavePath);
            await eventLogic.SaveLogs(CurrentUserSession.AttendesID.Value, "User profile", "Updated User Profile", "Updating User Details");

            return(Json(true));
        }
        public async Task <ActionResult> SpeakerById(string Token, int id)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           x = await attendesBusiness.GetAttendesById(id);

            return(Json(new
            {
                data = new
                {
                    x.ID,
                    x.FirstName,
                    x.Lastname,
                    x.Description,
                    Thumbnail = imageToUrlConvertionHandler(x.Thumbnail),
                    x.Status,
                    x.TitleName,
                    x.CompanyName,
                    Documents = x.Documents.Select(y => new
                    {
                        y.ID,
                        y.DocumentName,
                        FilePath = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, MvcCustom.ApiDocumentPath(y.FilePath))
                    }),
                    Activities = x.BookMarks.Select(y => new
                    {
                        y.Activite.ID,
                        y.Activite.Name,
                        y.Activite.StartTime,
                        y.Activite.EndTime,
                        Thumbnail = imageToUrlConvertionHandler(y.Activite.Thumbnail)
                    }),
                    x.LinkedinURL,
                    x.FacebookURL,
                    x.TwitterURL,
                    x.Website,
                    x.InstagramURL,
                    x.EnableMessaging
                }
            }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> GetAttendeeForSpecificEvent(string Token, int EventId)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           data             = await attendesBusiness.GetAttendeeForSpecificEvent(EventId);

            return(Json(data.Select(x => new
            {
                x.ID,
                x.FirstName,
                x.Description,
                Thumbnail = imageToUrlConvertionHandler(x.Thumbnail),
                x.FacebookURL,
                x.TwitterURL,
                x.InstagramURL,
                x.Status,
                x.Email,
                x.LinkedinURL,
                x.Lastname,
                x.TitleName,
                x.CompanyName
            }), JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> GetSpeakerForSpecificEvent(string Token, int eventId)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           data             = await attendesBusiness.GetAttendeeForSpecificEvent(eventId, new SpeakerValidator());

            return(Json(data.Select(x => new
            {
                x.ID,
                x.FirstName,
                x.Description,
                Thumbnail = imageToUrlConvertionHandler(x.Thumbnail), // Helpers.ImageToBase64(MvcCustom.APiImagePath(x.Thumbnail)),
                x.FacebookURL,
                x.TwitterURL,
                x.InstagramURL,
                x.Status,
                x.Email,
                x.LinkedinURL,
                x.Lastname,
                x.TitleName,
                x.CompanyName,
                x.EnableMessaging
            }), JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Userprofile(string Token)
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           x = await attendesBusiness.GetAttendesById(CurrentUserSession.AttendesID.Value);

            return(Json(new
            {
                data = new
                {
                    x.AddedON,
                    x.Description,
                    x.Email,
                    x.FirstName,
                    x.Lastname,
                    x.InstagramURL,
                    x.LinkedinURL,
                    Thumbnail = imageToUrlConvertionHandler(x.Thumbnail),
                    //Helpers.ImageToBase64(MvcCustom.APiImagePath(x.Thumbnail)),
                    x.TwitterURL,
                    x.Status,
                    x.FacebookURL,
                }
            }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// Change Photos to base64
        /// </summary>
        /// <param name="token"></param>
        /// <param name="base64String"></param>
        /// <returns>Returns status of conversion</returns>

        public async Task <ActionResult> ChangePhotos(string token, string base64String)
        {
            if (base64String == "")
            {
                throw new APIException("Null image file.");
            }
            AttendesLogic alogic     = new AttendesLogic();
            var           uniquename = Guid.NewGuid(); // await alogic.UniqueAttendeeID(CurrentUserSession.AttendesID.Value);
            string        name       = uniquename + ".png";

            var result = alogic.ChangePhoto(CurrentUserSession.AttendesID.Value, name);

            byte[]       imageBytes = Convert.FromBase64String(base64String);
            MemoryStream ms         = new MemoryStream(imageBytes, 0, imageBytes.Length);

            ms.Write(imageBytes, 0, imageBytes.Length);
            Image image = Image.FromStream(ms, true);

            image.Save(Path.Combine(ImageSavePath, name));
            string jsonkeysfilepath = HttpRuntime.AppDomainAppPath + @"\" + GoogleDriveSync.jsonkeysfile;

            GoogleDriveSync.CallSaveApi(jsonkeysfilepath, "Profile Pictures", Path.Combine(ImageSavePath, name));
            return(Json(new { Data = "Success" }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Index(string Token, string term = "")
        {
            AttendesLogic attendesBusiness = new AttendesLogic();
            var           data             = await attendesBusiness.GetAttendes(term);

            return(Json(new
            {
                data = data.Select(x => new
                {
                    x.ID,
                    x.AddedON,
                    x.Description,
                    x.Email,
                    x.FirstName,
                    x.LinkedinURL,
                    x.InstagramURL,
                    Thumbnail = imageToUrlConvertionHandler(x.Thumbnail),
                    //Helpers.ImageToBase64(MvcCustom.APiImagePath(x.Thumbnail)),
                    x.TwitterURL,
                    x.Status,
                    x.FacebookURL,
                })
            }, JsonRequestBehavior.AllowGet));
        }
        // GET: Reports
        public async Task <ActionResult> Index(string SenderName = null, string AdminName = null, DateTime?Startdate = null, DateTime?Enddate = null, string SelectLevel = null)
        {
            try
            {
                AttendesLogic attendesLogic             = new AttendesLogic();
                IEnumerable <SelectListItem> AdminNames = db.Attendes.Where(x => x.IsAdmin == true).Select(n => new SelectListItem {
                    Text = n.FirstName, Value = n.FirstName
                }).ToList();
                //(await attendesLogic.GetAttendes(checkAttendeeValidity: new AtteendeeValidator())).Select(n => new SelectListItem { Text = n.FirstName, Value = n.FirstName }).OrderBy(s => s.Text).ToList();

                IEnumerable <EventSurveyData> eventdata = db.Events.Select(x => new EventSurveyData {
                    EventID = x.ID, EventName = x.EventName
                }).ToList();
                ViewBag.Events = eventdata;

                ViewBag.AdminNames = AdminNames;

                if (AdminName != null && Startdate == null && Enddate == null)
                {
                    ViewBag.TextChat = db.TextChats.Where(s => (s.Attende.FirstName == AdminName || s.Attende1.FirstName == AdminName) && s.IsGroup == true).ToList();
                }
                else if (AdminName == null && Startdate != null && Enddate != null)
                {
                    ViewBag.TextChat = db.TextChats.Where(s => (s.Createdate >= Startdate) && (s.Createdate <= Enddate) && s.IsGroup == true).ToList();
                }
                else if (AdminName != null && Startdate != null && Enddate != null)
                {
                    ViewBag.TextChat = db.TextChats.Where(s => (s.Attende.FirstName == AdminName || s.Attende1.FirstName == AdminName) && (s.Createdate >= Startdate) && (s.Createdate <= Enddate) && s.IsGroup == true).ToList();
                }
                else
                {
                    ViewBag.TextChat = db.TextChats.Where(s => s.IsGroup == true).ToList();
                }

                IEnumerable <SelectListItem> AttendeesNames = db.Attendes.Select(n => new SelectListItem {
                    Text = n.FirstName, Value = n.FirstName
                }).OrderBy(s => s.Text).ToList();
                ViewBag.AttendeeList = AttendeesNames;

                if (SenderName != null && Startdate == null && Enddate == null)
                {
                    ViewBag.UserMessages = db.TextChats.Where(s => s.Attende1.FirstName == SenderName || s.Attende.FirstName == SenderName).ToList();
                }
                else if (SenderName == null && Startdate != null && Enddate != null)
                {
                    ViewBag.UserMessages = db.TextChats.Where(s => (s.Createdate >= Startdate) && (s.Createdate <= Enddate)).ToList();
                }
                else if (SenderName != null && Startdate != null && Enddate != null)
                {
                    ViewBag.UserMessages = db.TextChats.Where(s => (s.Attende1.FirstName == SenderName || s.Attende.FirstName == SenderName) && (s.Createdate >= Startdate) && (s.Createdate <= Enddate)).ToList();
                }
                else
                {
                    ViewBag.UserMessages = new List <TextChat>();
                }

                ViewBag.AppUsage = db.UserSessions
                                   .Where(m => m.Platform == "Android" || m.Platform == "IOS")
                                   .GroupBy(n => n.Platform)
                                   .Select(n => new AppUsage
                {
                    Platform = n.Key,
                    count    = n.Select(x => x.DeviceToken)
                               .Distinct().Count()
                }).ToList();

                ViewBag.AppDownloads = commonLogic.GetAppDownloadsReport();

                ViewBag.TopSavedActivities = db.BookMarks
                                             .GroupBy(s => s.Activite.Name)
                                             .Select(n => new TopSavedActivities
                {
                    Name  = n.Key,
                    count = n.Select(x => x.Activite.Name).Count()
                })
                                             .OrderByDescending(o => o.count)
                                             .Take(10)
                                             .ToList();


                ViewBag.TopVisitedPages = db.Sys_Log.GroupBy(s => s.Page)
                                          .Select(n => new TopVisitedPages
                {
                    Page  = n.Key,
                    count = n.Select(x => x.Page).Count()
                })
                                          .OrderByDescending(o => o.count)
                                          .Take(10)
                                          .ToList();

                ViewBag.DownloadPhotos = db.Sys_Log.Where(s => s.Page == "Download picture")
                                         .GroupBy(s => s.Attende.FirstName)
                                         .Select(n => new DownloadPhotos
                {
                    Name  = n.Key,
                    count = n.Select(x => x.ModifiedBy).Count()
                })
                                         .OrderByDescending(o => o.count)
                                         .Take(10)
                                         .ToList();

                if (SelectLevel == "Event")
                {
                    ViewBag.QuestionResponses = db.Responses.
                                                Join(db.Questions, response => response.QuestionID, question => question.ID, (response, question) => new { response, question }).
                                                Where(x => x.question.Survey.SurveyLevel == "Event Level" &&
                                                      x.question.ResponseType.ResponseName != "Text").
                                                GroupBy(s => new { s.response.QuestionID, s.response.OptionsSelected }).
                                                Select(n => new SurveyReport
                    {
                        Question  = db.Questions.FirstOrDefault(x => x.ID == n.Key.QuestionID).QuestionText,
                        Responses = db.Options.FirstOrDefault(x => x.ID.ToString() == n.Key.OptionsSelected).option1,
                        Count     = n.Select(x => x.response.OptionsSelected).Count()
                    })
                                                .OrderByDescending(o => o.Count)
                                                .ToList();
                    ViewBag.Level = "Event";
                }
                else if (SelectLevel == "App")
                {
                    ViewBag.QuestionResponses = db.Responses.ToList().
                                                Join(db.Questions, response => response.QuestionID, question => question.ID, (response, question) => new { response, question }).
                                                Where(x => x.question.Survey.SurveyLevel == "App Level" && x.question.ResponseType.ResponseName == "Rating").
                                                GroupBy(s => new { s.response.QuestionID }).
                                                Select(n => new SurveyReport
                    {
                        Question = db.Questions.FirstOrDefault(x => x.ID == n.Key.QuestionID).QuestionText,
                        Average  = Math.Round(n.Select(x => Convert.ToInt32(x.response.OptionsSelected)).ToList().Average(), 2)
                    }).ToList();
                    ViewBag.Level = "App";
                }
                else if (SelectLevel == "Activity")
                {
                    ViewBag.QuestionResponses = db.Responses.
                                                Join(db.Questions, response => response.QuestionID, question => question.ID, (response, question) => new { question, response }).
                                                Where(x => x.question.Survey.SurveyLevel == "Activity Level").
                                                GroupBy(s => new { s.response.QuestionID, s.response.OptionsSelected }).
                                                Select(n => new SurveyReport
                    {
                        Question  = db.Questions.FirstOrDefault(x => x.ID == n.Key.QuestionID).QuestionText,
                        Responses = db.Options.FirstOrDefault(x => x.ID.ToString() == n.Key.OptionsSelected).option1,
                        Count     = n.Select(x => x.response.OptionsSelected).Count()
                    })
                                                .OrderByDescending(o => o.Count)
                                                .ToList();
                    ViewBag.Level = "Activity";
                }
                else
                {
                    ViewBag.QuestionResponses = new List <SurveyReport>();
                }
                return(View());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // GET: API/Attendes
        public async Task <ActionResult> Index()
        {
            AttendesLogic attendesBusiness = new AttendesLogic();

            return(Json(new { data = await attendesBusiness.GetAttendes() }));
        }