public IEnumerable <Food> CreateUnknownFoods(DateTime startOfWeek) { var dateInPersian = new PersianDateTime(startOfWeek).AddDays(-1); var dateInGeorgian = startOfWeek.AddDays(-1); List <Food> result = new List <Food>(); for (int i = 0; i < 5; i++) { dateInPersian = dateInPersian.AddDays(+1); dateInGeorgian = dateInGeorgian.AddDays(+1); var newFood = new Food() { Date = dateInGeorgian, PersianDate = dateInPersian.ToShortDateInt(), }; result.Add(newFood); } _foodRepository.Insert(result.ToArray()); return(result); }
public static ConcurrentDictionary <int, List <DayModel> > DeserializeJson(int persianYear, int persianMonth) { string json; try { var path = Path.Combine(Directory.GetCurrentDirectory(), JsonFilename); using var reader = new StreamReader(path); json = reader.ReadToEnd(); } catch (Exception ex) { Console.WriteLine(ex); json = ""; } if (string.IsNullOrEmpty(json)) { return(new ConcurrentDictionary <int, List <DayModel> >()); } var calendars = JToken.Parse(json); var monthResult = Init(); foreach (var calendar in calendars) { var calendarName = calendar["name"].ToString(); var calendarEvents = calendar["event"]; var date = (from month in calendarEvents select new MonthModel { MonthNo = Convert.ToInt32(((JProperty)month).Name), Days = (from day in month.First let @event = day.First.First["event"].Value <string>() let holiday = day.First.First["holiday"].Value <string>() let dayNo = Convert.ToInt32(((JProperty)day).Name) select new DayModel { DayOfMonth = dayNo, Events = @event.Split(new[] { "\r\n", "/", "؛" }, StringSplitOptions.None) .Select(x => x.Trim()).ToList(), IsHoliday = holiday == "1" }).ToList(), }).ToList(); if (date.Count <= 0) { continue; } DateTime rangeFrom; DateTime rangeTo; CalendarTypes calendarType; switch (calendarName) { case "jalali": rangeFrom = new PersianDateTime(persianYear, persianMonth, 1).ToDateTime(); rangeTo = new PersianDateTime(persianYear, persianMonth, GetMonthDays(persianMonth)).ToDateTime(); calendarType = CalendarTypes.Persian; break; case "miladi": rangeFrom = new PersianDateTime(persianYear, persianMonth, 1).ToDateTime(); rangeTo = new PersianDateTime(persianYear, persianMonth, GetMonthDays(persianMonth)).ToDateTime(); calendarType = CalendarTypes.Gregorian; break; case "hijri": default: rangeFrom = new PersianDateTime(persianYear, persianMonth, 1).ToDateTime(); rangeTo = new PersianDateTime(persianYear, persianMonth, GetMonthDays(persianMonth)).ToDateTime(); calendarType = CalendarTypes.Hijri; break; } var ranges = Enumerable.Range(0, rangeTo.Subtract(rangeFrom).Days + 1) .Select(d => rangeFrom.AddDays(d)).ToList(); monthResult.UpdateLibrary(date, ranges, calendarType); } return(monthResult); }
public static string MakeCalender(int year) { if (year == 0) { year = new PersianDateTime(DateTime.Now).Year; } var persiandate = new PersianDateTime(year, 1, 1); string res = ""; for (int i = 1; i < 5; i++) { res += "<div class='row'>"; for (int j = 1; j < 4; j++) { res += "<div class='col-md-4' style='text-align: center'>"; res += "<div class='cal'>"; res += " <table class='cal-table'>"; res += "<caption class='cal-caption'>"; res += persiandate.GetLongMonthName; //res += monthCounter.ToString(); res += "</caption>"; res += "<tbody class='cal-body'>"; int emptyCells = ((int)persiandate.DayOfWeek + 7 - 6) % 7; int days = persiandate.GetMonthDays; for (int k = 0; k != 42; k++) { if (k % 7 == 0) { res += "<tr>"; if (k > 0) res += "</tr>"; } if (k < emptyCells || k >= emptyCells + days) { res += "<td class='cal-off'><a href='#'>"; res += "-"; res += "</a></td>"; } else { if (!string.IsNullOrWhiteSpace(TodayVM.GetPersianEvent(persiandate.Month, persiandate.Day))) res += "<td title='" + TodayVM.GetPersianEvent(persiandate.Month, persiandate.Day) + "'" + " class='cal-check'>"; else { if (persiandate.ToDateTime().Date == DateTime.Now.Date) res += "<td class='cal-today'>"; else res += "<td >"; } if (persiandate.DayOfWeek == DayOfWeek.Friday) res += "<a style='color:red;'>"; else res += "<a>"; var dayNo = "12"; res += TodayVM.ToPersianDigit(persiandate.Day.ToString()); res += "</a></td>"; persiandate = persiandate.AddDays(1); } } res += "</tbody>"; res += "</table>"; res += "</div>"; res += "</div>"; persiandate.AddMonths(1); } res += "</div>"; } return res; }