public CalendarModel generateCalendar(YearMonthModel ymmodel)//, string userID) { //create a new calendar model CalendarModel newCalendar = new CalendarModel(); //get bankholidays, vacations and populate calendar var bankholidays = BhR.GetBankHolidays(); var vacations = Vacations.GetVacations(); newCalendar.monthdays = new System.Collections.Generic.List <DayModel>(); newCalendar.bankholidays = bankholidays; newCalendar.vacations = vacations; //get our month days number and parse it var mdays = DateTime.DaysInMonth(ymmodel.year, ymmodel.month); for (var iter = 1; iter <= mdays; iter++) { //default values for descriptions and freeday var descriptionStatus = "busy"; var isFreeDayStatus = false; //next day and check if its weekend, bankholiday or vacation day var currentDate = new DateTime(ymmodel.year, ymmodel.month, iter); if ((currentDate.DayOfWeek == DayOfWeek.Saturday) || (currentDate.DayOfWeek == DayOfWeek.Sunday)) { descriptionStatus = "Weekend"; isFreeDayStatus = true; } if (bankholidays.Any(x => x.Month == currentDate.Month && x.Day == iter)) { isFreeDayStatus = true; descriptionStatus += " BankHoliday"; } var CurrentUserID = User.Identity.GetUserId(); var check = newdb.UserDetails.FirstOrDefault(d => d.UserID == CurrentUserID); if (vacations.Any(x => x.UserId == check.ID && x.StartDate <= currentDate && x.EndDate >= currentDate && x.StateId == 1)) { descriptionStatus += " Want to go to Vacation"; } if (vacations.Any(x => x.UserId == check.ID && x.StartDate <= currentDate && x.EndDate >= currentDate && x.StateId == 2)) { isFreeDayStatus = true; descriptionStatus += " Vacation"; } //add it to our list newCalendar.monthdays.Add(new DayModel { description = descriptionStatus, day = iter, name = currentDate.ToString("dddd"), isFreeDay = isFreeDayStatus }); } //return our calendar return(newCalendar); }
/// <summary> /// Initializes a new instance of the <see cref="View Attendance Summary Page"/> class. /// </summary> public ViewAttendanceSummary() { Device.BeginInvokeOnMainThread(async() => { try { _YearMonth = await YearMonthModel.GetYerRange(); ViewAttendanceSummaryLayout(); } catch (Exception ex) { } }); }
public ActionResult Index() { YearMonthModel temp = new YearMonthModel { month = DateTime.Now.Month, year = DateTime.Now.Year }; DashboardViewModel vM = new DashboardViewModel() { userID = User.Identity.GetUserId(), userL = db.GetUsers(), //Get the user’s list and pass it to the Model teamL = tdb.GetTeams(), //Get the team’s list and pass it to the Model roleL = newdb.Roles.ToList(), calendar = generateCalendar(temp) }; return(View(vM)); }
private void VacationClosingEventHandler(object sender, DialogClosingEventArgs eventArgs) { if ((bool)eventArgs.Parameter == false) { return; } eventArgs.Cancel(); var dialogViewContent = (MonthOptionsDialogView)eventArgs.Content; var dialogData = (MonthOptionsDialogViewModel)dialogViewContent.DataContext; YearMonthModel tempYearMonth = new YearMonthModel { Year = dialogData.SelectedDate.Year, Month = dialogData.SelectedDate.Month, MonthsWorkingHours = dialogData.MonthsWorkingHours, MonthsWeekendDays = new HashSet <int>(Array.ConvertAll(dialogData.WeekendDays.Split(';'), int.Parse)) }; eventArgs.Session.UpdateContent(new ProgressDialog()); using (_dbContext = new WHTDbContext()) { if (_dbContext.YearMonths.Any(x => x.Year.Equals(tempYearMonth.Year) && x.Month.Equals(tempYearMonth.Month))) { _dbContext.Entry(tempYearMonth).State = System.Data.Entity.EntityState.Modified; } else { _dbContext.Entry(tempYearMonth).State = System.Data.Entity.EntityState.Added; } _dbContext.SaveChanges(); } Task.Delay(TimeSpan.FromSeconds(1)) .ContinueWith((t, _) => eventArgs.Session.Close(false), null, TaskScheduler.FromCurrentSynchronizationContext()); GetAndSetAllInfoFromDatabase(); NotifyOfPropertyChange(() => SelectedDate); }
public async Task <GraphModel> GetGraphData(string start, string currency, string baseCurrency) { string currentDate = (await _currencyService.GetLatestRates("EUR")).Date; YearMonthModel checkDate = new YearMonthModel(start); YearMonthModel today = new YearMonthModel(currentDate); List <string> dates = new List <string>(); List <double> rates = new List <double>(); while (!checkDate.Equals(today)) { CurrencyModel wantedRate; if (!_cache.TryGetValue(currency + checkDate.ToString(), out wantedRate)) { ResponseModel dateRates = await _currencyService.GetCertainDateRate(checkDate.ToString(), baseCurrency); wantedRate = dateRates.DeserRates.FirstOrDefault(rate => rate.CurrencyType == currency); if (wantedRate == null) { return(null); } _cache.Set(wantedRate.CurrencyType + checkDate.ToString(), wantedRate); } dates.Add(checkDate.ToString()); rates.Add(wantedRate.ExchangeRate); checkDate.Month++; } GraphModel result = new GraphModel() { Dates = dates, Rates = rates, CurrencyType = currency, BaseCurrencyType = baseCurrency }; return(result); }
public void InitDummyData() { Database.SetInitializer <WHTDbContext>(new DropCreateDatabaseAlways <WHTDbContext>()); EmployeeModel tempEmp = new EmployeeModel { FirstName = "Adam", LastName = "Oforek" }; Employees.Add(tempEmp); tempEmp = new EmployeeModel { FirstName = "Marek", LastName = "Janek" }; Employees.Add(tempEmp); tempEmp = new EmployeeModel { FirstName = "Aneta", LastName = "Polak" }; Employees.Add(tempEmp); tempEmp = new EmployeeModel { FirstName = "Cesarz", LastName = "Juliusz" }; Employees.Add(tempEmp); DateTime now = new DateTime(); now = DateTime.Now.Date; HoursModel tempHours = new HoursModel { WorkingDate = now, From = new TimeSpan(8, 30, 0), To = new TimeSpan(17, 0, 0), EmployeeId = 1 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now.AddDays(-1), From = new TimeSpan(7, 00, 0), To = new TimeSpan(17, 0, 0), EmployeeId = 1 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now, From = new TimeSpan(6, 30, 0), To = new TimeSpan(10, 0, 0), EmployeeId = 2 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now.AddDays(-14), From = new TimeSpan(6, 30, 0), To = new TimeSpan(10, 0, 0), EmployeeId = 1 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now, From = new TimeSpan(6, 30, 0), To = new TimeSpan(10, 0, 0), EmployeeId = 3 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now, From = new TimeSpan(6, 30, 0), To = new TimeSpan(10, 0, 0), EmployeeId = 4 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now.AddDays(-3), From = new TimeSpan(6, 30, 0), To = new TimeSpan(10, 0, 0), EmployeeId = 1 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now.AddDays(-3), From = new TimeSpan(6, 30, 0), To = new TimeSpan(10, 0, 0), EmployeeId = 2 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now.AddDays(-3), From = new TimeSpan(6, 30, 0), To = new TimeSpan(10, 0, 0), EmployeeId = 3 }; Hours.Add(tempHours); tempHours = new HoursModel { WorkingDate = now.AddDays(-3), From = new TimeSpan(6, 30, 0), To = new TimeSpan(10, 0, 0), EmployeeId = 4 }; Hours.Add(tempHours); HashSet <int> weekends = new HashSet <int>(); weekends.Add(1); weekends.Add(3); weekends.Add(4); weekends.Add(5); weekends.Add(11); weekends.Add(12); weekends.Add(18); weekends.Add(19); weekends.Add(25); weekends.Add(26); YearMonthModel yearMonth = new YearMonthModel { Year = 2019, Month = 5, MonthsWorkingHours = 168, MonthsWeekendDays = new HashSet <int>(weekends) }; YearMonths.Add(yearMonth); YearMonths.Add(yearMonth); yearMonth = new YearMonthModel { Year = 2019, Month = 6, MonthsWorkingHours = 160, MonthsWeekendDays = new HashSet <int>(weekends) }; YearMonths.Add(yearMonth); yearMonth = new YearMonthModel { Year = 2019, Month = 7, MonthsWorkingHours = 200, MonthsWeekendDays = new HashSet <int>(weekends) }; YearMonths.Add(yearMonth); VacationModel vacation = new VacationModel { From = DateTime.Now, To = DateTime.Now.AddDays(7), Type = Models.Enums.VacationTypes.PŁATNY, EmployeeId = 1 }; Vacations.Add(vacation); vacation = new VacationModel { From = DateTime.Now, To = DateTime.Now.AddDays(3), Type = Models.Enums.VacationTypes.ZWOLNIENIE_LEKARSKIE, EmployeeId = 2 }; Vacations.Add(vacation); vacation = new VacationModel { From = DateTime.Now, To = DateTime.Now.AddDays(3), Type = Models.Enums.VacationTypes.OKOLICZNOŚCIOWY, EmployeeId = 3 }; Vacations.Add(vacation); vacation = new VacationModel { From = DateTime.Now, To = DateTime.Now.AddDays(3), Type = Models.Enums.VacationTypes.RODZICIELSKI, EmployeeId = 1 }; Vacations.Add(vacation); vacation = new VacationModel { From = DateTime.Now, To = DateTime.Now.AddDays(3), Type = Models.Enums.VacationTypes.WYPOCZYNKOWY, EmployeeId = 4 }; Vacations.Add(vacation); vacation = new VacationModel { From = DateTime.Now, To = DateTime.Now.AddDays(3), Type = Models.Enums.VacationTypes.ZWOLNIENIE_LEKARSKIE, EmployeeId = 2 }; Vacations.Add(vacation); vacation = new VacationModel { From = DateTime.Now, To = DateTime.Now.AddDays(3), Type = Models.Enums.VacationTypes.RODZICIELSKI, EmployeeId = 3 }; Vacations.Add(vacation); vacation = new VacationModel { From = DateTime.Now, To = DateTime.Now.AddDays(3), Type = Models.Enums.VacationTypes.ZWOLNIENIE_LEKARSKIE, EmployeeId = 4 }; Vacations.Add(vacation); this.SaveChanges(); }