public string CreateCSV(List <WeeklyActivityCSV> ListOfActivities, string FileName, string PlayerName, string PlayerEmailAddress, string LeagueName, Controller ctrl)
        {
            string            CSVFilePath = "";
            WeeklyActivityCSV dataCSV     = new WeeklyActivityCSV();

            var output = dataCSV.ToCsvHeader();

            output += Environment.NewLine;

            ListOfActivities.ForEach(data =>
            {
                output += data.ToCsvRow();
                output += Environment.NewLine;
            });

            output += "-------------------------------------";
            output += Environment.NewLine;

            output += "Player Name: " + PlayerName;
            output += Environment.NewLine;

            output += "Email Address: " + PlayerEmailAddress;
            output += Environment.NewLine;

            output += "League Name: " + LeagueName;
            output += Environment.NewLine;

            try
            {
                var path = ctrl.Server.MapPath(SecurityUtils.ActivityData_Path);

                //if Directory is not exists then create one
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                CSVFilePath = System.IO.Path.Combine(path, FileName);

                System.IO.File.WriteAllText(CSVFilePath, output);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //if(System.IO.File.Exists(path))
                //{
                //    System.IO.File.Delete(path);
                //}
            }

            return(CSVFilePath);
        }
        public WeeklyActivityCSV MAP_To_CSV(PlayerWeeklyActivities model)
        {
            WeeklyActivityCSV m = new WeeklyActivityCSV()
            {
                ActivityDate = model.ActivityDate.ToString("dd/MM/yyyy"),
                Activity     = model.Activity,
                ActivityTime = ActivityMinutesToString(model.ActivityTime),
                Completed    = model.Completed ? "Yes" : "No"
            };

            return(m);
        }
        public List <WeeklyActivityCSV> CreateListOfActivities(ShareActivity model, Controller ctrl)
        {
            List <WeeklyActivityCSV> ListOfActivitiesCSV = new List <WeeklyActivityCSV>();

            if (model.ShareFrequencyID == 1) //Today
            {
                DateTime TodayDate = DateTime.Now.Date;

                var StartDateOfWeek = DateTimeExtensions.StartOfWeek(TodayDate, DayOfWeek.Monday);
                var EndDateOfWeek   = StartDateOfWeek.AddDays(6);

                var Activities = db.PlayerWeeklyActivities.Where(m => m.PlayerID == model.PlayerID && (m.ActivityDate >= StartDateOfWeek && m.ActivityDate <= EndDateOfWeek)).OrderBy(o => o.ActivityDate).ToList().Select(m => MAP_To_CSV(m)).ToList();

                for (DateTime loopDate = StartDateOfWeek; loopDate <= EndDateOfWeek; loopDate = loopDate.AddDays(1))
                {
                    if (Activities.Any(m => IsDateMatched(m.ActivityDate, loopDate)) == false)
                    {
                        WeeklyActivityCSV m = new WeeklyActivityCSV()
                        {
                            ActivityDate = loopDate.ToString("dd/MM/yyyy"),
                            Activity     = "",
                            ActivityTime = "",
                            Completed    = ""
                        };

                        Activities.Add(m);
                    }
                }

                ListOfActivitiesCSV.AddRange(Activities);
            }
            else if (model.ShareFrequencyID == 2) //Last 7 Days
            {
                var StartDateOfWeek = DateTimeExtensions.StartOfWeek(DateTime.Now.Date.AddDays(-7), DayOfWeek.Monday);
                var EndDateOfWeek   = StartDateOfWeek.AddDays(6);

                var Activities = db.PlayerWeeklyActivities.Where(m => m.PlayerID == model.PlayerID && (m.ActivityDate >= StartDateOfWeek && m.ActivityDate <= EndDateOfWeek)).OrderBy(o => o.ActivityDate).ToList().Select(m => MAP_To_CSV(m)).ToList();

                for (DateTime loopDate = StartDateOfWeek; loopDate <= EndDateOfWeek; loopDate = loopDate.AddDays(1))
                {
                    if (Activities.Any(m => IsDateMatched(m.ActivityDate, loopDate)) == false)
                    {
                        WeeklyActivityCSV m = new WeeklyActivityCSV()
                        {
                            ActivityDate = loopDate.ToString("dd/MM/yyyy"),
                            Activity     = "",
                            ActivityTime = "",
                            Completed    = ""
                        };

                        Activities.Add(m);
                    }
                }

                ListOfActivitiesCSV.AddRange(Activities);
            }
            else if (model.ShareFrequencyID == 3) //Last Month
            {
                var StartDateOfWeek = DateTimeExtensions.StartOfWeek(DateTime.Now.Date.AddDays(-30), DayOfWeek.Monday);
                var EndDateOfWeek   = DateTime.Now.Date;

                var Activities = db.PlayerWeeklyActivities.Where(m => m.PlayerID == model.PlayerID && (m.ActivityDate >= StartDateOfWeek && m.ActivityDate <= EndDateOfWeek)).OrderBy(o => o.ActivityDate).ToList().Select(m => MAP_To_CSV(m)).ToList();

                for (DateTime loopDate = StartDateOfWeek; loopDate <= EndDateOfWeek; loopDate = loopDate.AddDays(1))
                {
                    if (Activities.Any(m => IsDateMatched(m.ActivityDate, loopDate)) == false)
                    {
                        WeeklyActivityCSV m = new WeeklyActivityCSV()
                        {
                            ActivityDate = loopDate.ToString("dd/MM/yyyy"),
                            Activity     = "",
                            ActivityTime = "",
                            Completed    = ""
                        };

                        Activities.Add(m);
                    }
                }

                ListOfActivitiesCSV.AddRange(Activities);
            }
            else if (model.ShareFrequencyID == 4) //Date Range
            {
                var StartDate = model.Activity_ShareDateFrom.Value;
                var EndDate   = model.Activity_ShareDateTo.Value;

                var Activities = db.PlayerWeeklyActivities.Where(m => m.PlayerID == model.PlayerID && (m.ActivityDate >= StartDate && m.ActivityDate <= EndDate)).OrderBy(o => o.ActivityDate).ToList().Select(m => MAP_To_CSV(m)).ToList();

                for (DateTime loopDate = StartDate; loopDate <= EndDate; loopDate = loopDate.AddDays(1))
                {
                    if (Activities.Any(m => IsDateMatched(m.ActivityDate, loopDate)) == false)
                    {
                        WeeklyActivityCSV m = new WeeklyActivityCSV()
                        {
                            ActivityDate = loopDate.ToString("dd/MM/yyyy"),
                            Activity     = "",
                            ActivityTime = "",
                            Completed    = ""
                        };

                        Activities.Add(m);
                    }
                }

                ListOfActivitiesCSV.AddRange(Activities);
            }

            return(ListOfActivitiesCSV);
        }