Ejemplo n.º 1
0
        private IEnumerable <Food> AaMenu()
        {
            const string range     = AlwaysAvailableSheet + "!A2:A1000";
            ValueRange   sheetData = GoogleSheetService.GetColumns(_sheetId, range);

            // Null and empty check
            if (!(sheetData?.Values?.Any() == true))
            {
                return(new List <Food>());
            }

            return(sheetData.Values.First().Select(f => new Food {
                Name = f.ToString(), Restaurant = _restaurant
            }).ToList());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get food from daily menu for today
        /// </summary>
        /// <returns>List of today available food</returns>
        private IEnumerable <Food> DailyMenu()
        {
            const string range     = DailyMenuSheet + "!A3:A100";
            ValueRange   sheetData = GoogleSheetService.GetColumns(_sheetId, range);

            // Null and empty check
            if (!(sheetData?.Values?.Any() == true))
            {
                return(new List <Food>());
            }
            else
            {
                var result = sheetData.Values.First().Select(f => new Food {
                    Name = f.ToString(), Restaurant = _restaurant
                }).ToList();
                return(result);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Setup daily menu sheet, making today first column
        /// </summary>
        public void DnevniMenuSheetSetup()
        {
            // Get data
            ValueRange sheetData = GoogleSheetService.GetColumns(SheetId, DailyMenuSheet);

            DateTime dateCounter = DateTime.Today;

            var sheetValues = sheetData.Values;
            var dayOfWeek   = GetLocalDayName(dateCounter.DayOfWeek);
            int today       = 0;

            for (int i = 0; i < sheetValues.Count; i++)
            {
                if (sheetValues[i][0].ToString() == dayOfWeek)
                {
                    today = i;
                }
            }

            ValueRange updatedRange = new ValueRange {
                Values = new List <IList <object> >()
            };
            const int daysToAdd = 0;

            // Insert today and after
            for (int i = today; i < sheetValues.Count; i++)
            {
                sheetValues[i][1] = dateCounter.AddDays(daysToAdd).ToString("dd-MM-yyyy");
                updatedRange.Values.Add(sheetValues[i]);
                if (dateCounter.DayOfWeek == DayOfWeek.Friday)
                {
                    dateCounter = dateCounter.AddDays(3);
                }
                else
                {
                    dateCounter = dateCounter.AddDays(1);
                }
            }

            // Insert before today
            for (int k = 0; k < today; k++)
            {
                sheetValues[k][1] = dateCounter.AddDays(daysToAdd).ToString("dd-MM-yyyy");
                updatedRange.Values.Add(sheetValues[k]);
                if (dateCounter.DayOfWeek == DayOfWeek.Friday)
                {
                    dateCounter = dateCounter.AddDays(3);
                }
                else
                {
                    dateCounter = dateCounter.AddDays(1);
                }
            }

            // Transpose values
            ValueRange formatedRange = new ValueRange {
                Values = new List <IList <object> >()
            };

            bool empty  = true;
            int  rowNum = 0;

            do
            {
                empty = true;
                List <object> row = new List <object>();
                for (int i = 0; i < updatedRange.Values.Count; i++)
                {
                    if (updatedRange.Values[i].Count > rowNum)
                    {
                        row.Add(updatedRange.Values[i][rowNum].ToString());
                        empty = false;
                    }
                    else
                    {
                        row.Add(string.Empty);
                    }
                }

                if (!empty)
                {
                    formatedRange.Values.Add(row);
                    rowNum++;
                }
            }while (!empty);

            GoogleSheetService.Clear(SheetId, DailyMenuSheet);
            GoogleSheetService.Update(formatedRange, SheetId, DailyMenuSheet);
        }