Beispiel #1
0
        public IActionResult Day(DateTime date)
        {
            // find users events for given date
            var userId = GetCurrentUserId();
            var events = context.Events.Where(a => a.Date == date && a.User.Id == userId);

            // map events to EventViewModel
            var eventsViewModel = events.Select(a => new EventViewModel
            {
                Id          = a.Id,
                Description = a.Description,
                End         = a.End,
                Start       = a.Start,
                Title       = a.Title
            }).OrderBy(a => a.Start).ToList();


            var model = new DayViewModel
            {
                FullDate     = date,
                DayName      = calendarService.GetDayName(date),
                MonthNameDop = calendarService.GetMonthNameDop(date),
                DayNumber    = date.Day,
                Events       = eventsViewModel
            };

            return(View(model));
        }
Beispiel #2
0
        public CalendarViewModel Build()
        {
            DayViewModel[,] days = new DayViewModel[6, 7];
            DateTime date   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            int      offset = (int)date.DayOfWeek;

            if (offset == 0)
            {
                offset = 7;
            }

            offset--;
            date = date.AddDays(offset * -1);

            for (int i = 0; i != 6; i++)
            {
                for (int j = 0; j != 7; j++)
                {
                    days[i, j] = new DayViewModelBuilder(this.Storage).Build(date);
                    date       = date.AddDays(1);
                }
            }

            return(new CalendarViewModel()
            {
                Date = DateTime.Now,
                Days = days
            });
        }
Beispiel #3
0
        private List <DayViewModel> GetLastWeek(Habit habit)
        {
            var days     = new List <DayViewModel>();
            var lastweek = habit.DayStatuses.Where(d => d.StatusDate.Date > DateTime.Now.Date.AddDays(-7)).OrderByDescending(d => d.StatusDate);

            foreach (var date in lastweek)
            {
                DayViewModel day = new DayViewModel();
                day.DayStatus = date.Status.StatusName;
                day.DayId     = date.DayStatusId;
                day.Date      = date.StatusDate;
                day.HasNote   = (date.NoteHeadline != null && date.NoteHeadline != "") || (date.Note != null && date.Note != "");
                day.WithDay   = true;
                days.Add(day);
            }

            if (days.Count < 7)
            {
                int disabled = 7 - days.Count;
                for (int i = 0; i < disabled; i++)
                {
                    DayViewModel day = new DayViewModel();
                    day.DayStatus = "disabled";
                    day.WithDay   = true;
                    days.Add(day);
                }
            }

            days.Reverse();

            return(days);
        }
Beispiel #4
0
        public GetMonthViewModel GetMonthViewModel(DateTime selectedMonth, List <ScheduledTask> tasks)
        {
            var previousMonth = selectedMonth.AddMonths(-1);
            var secondMonth   = selectedMonth.AddMonths(1);
            int d             = (int)selectedMonth.DayOfWeek;
            int se            = ((d == 0 ? 7 : d) - 1) * -1;

            var dayIterator = selectedMonth.AddDays(se);

            DayViewModel[,] days = new DayViewModel[6, 7];
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    days[i, j]                     = new DayViewModel();
                    days[i, j].DateTime            = dayIterator;
                    days[i, j].CountScheduledTasks = tasks.Count(x => x.DateTime.Year == dayIterator.Year && x.DateTime.Month == dayIterator.Month && x.DateTime.Day == dayIterator.Day);
                    dayIterator                    = dayIterator.AddDays(1);
                }
            }

            var getMonth = new GetMonthViewModel
            {
                SelectedMonth = selectedMonth,
                PreviousMonth = previousMonth,
                SecondMonth   = secondMonth,
                Days          = days
            };

            return(getMonth);
        }
 public void checkDays()
 {
     if (DateTime.Now.Hour > Settings.UpdateHour)             // && DateTime.Now.Minute > Settings.UpdateMinute)
     {
         _oggi = new DayViewModel()
         {
             Data = DateTime.Today.AddDays(1)
         };
         _domani = new DayViewModel()
         {
             Data = _oggi.Data.AddDays(1)
         };
         _dopodomani = new DayViewModel()
         {
             Data = _domani.Data.AddDays(1)
         };
     }
     else
     {
         _oggi = new DayViewModel()
         {
             Data = DateTime.Today
         };
         _domani = new DayViewModel()
         {
             Data = _oggi.Data.AddDays(1)
         };
         _dopodomani = new DayViewModel()
         {
             Data = _domani.Data.AddDays(1)
         };
     }
 }
Beispiel #6
0
        public async Task <IActionResult> Edit(int id, DayViewModel model)
        {
            int dayId = model.Day.DayId;

            if (id != dayId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (model.Uid != "")
                {
                    model.Day.Name = model.Day.Name.Prepend(model.Uid);
                }
                try
                {
                    await _db.UpdateDayAsync(model);
                }
                catch (Exception)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                return(Redirect(model.LastPage));
            }
            return(View(model));
        }
        /// <summary>
        /// Executes once LoadRequest has executed. Will also happen when deserializing cached data
        /// </summary>
        public override object Deserialize(DayLoadContext loadContext, Type objectType, Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            string html = PageParser.GetHtml(stream);

            List <Entry> entries   = PageParser.ExtractEntriesFromHtml(html, true);
            var          viewModel = new DayViewModel(loadContext);

            if (loadContext.ReverseOrder)
            {
                for (int i = entries.Count - 1; i >= 0; i--)
                {
                    viewModel.Highlights.Add(entries[i]);
                }
            }
            else
            {
                foreach (Entry entry in entries)
                {
                    viewModel.Highlights.Add(entry);
                }
            }

            return(viewModel);
        }
        /// <summary>
        /// Executes once LoadRequest has executed. Will also happen when deserializing cached data
        /// </summary>
        public override object Deserialize(DayLoadContext loadContext, Type objectType, Stream stream)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            string html = PageParser.GetHtml(stream);

            List<Entry> entries = PageParser.ExtractEntriesFromHtml(html, true);
            var viewModel = new DayViewModel(loadContext);

            if (loadContext.ReverseOrder)
            {
                for (int i = entries.Count - 1; i >= 0; i--)
                {
                    viewModel.Highlights.Add(entries[i]);
                }
            }
            else
            {
                foreach (Entry entry in entries)
                {
                    viewModel.Highlights.Add(entry);
                }
            }

            return viewModel;
        }
Beispiel #9
0
 public void Update(DayViewModel dayViewModel)
 {
     DateTicks = TimeZoneInfo.ConvertTimeToUtc(dayViewModel.Date).Ticks;
     StartTime = dayViewModel.StartTime.HasValue && dayViewModel.StartTime.Value.TotalSeconds != 0 ? (TimeSpan?)TimeZoneInfo.ConvertTimeToUtc(new DateTime(dayViewModel.StartTime.Value.Ticks), TimeZoneInfo.Local).TimeOfDay : null;
     EndTime   = dayViewModel.EndTime.HasValue && dayViewModel.EndTime.Value.TotalSeconds != 0 ? (TimeSpan?)TimeZoneInfo.ConvertTimeToUtc(new DateTime(dayViewModel.EndTime.Value.Ticks), TimeZoneInfo.Local).TimeOfDay : null;
     Holiday   = dayViewModel.Holiday;
 }
Beispiel #10
0
        public async Task UpdateDayAsync(DayViewModel model)
        {
            await UpdateAsync(model.Day);

            var daySubjects = await GetAllDaySubjectsAsync();

            model.CheckList.ForEach(async item =>
            {
                var existingEntry = daySubjects
                                    .FirstOrDefault(x => x.DayId == model.Day.DayId && x.SubjectId == item.Id);
                if (!item.IsSelected && existingEntry != null)
                {
                    await RemoveAsync(existingEntry);
                }

                if (item.IsSelected && existingEntry == null)
                {
                    DaySubject ds = new DaySubject()
                    {
                        DayId     = model.Day.DayId,
                        SubjectId = item.Id
                    };
                    _context.Add(ds);
                }
            });

            await _context.SaveChangesAsync();
        }
        public static DayViewModel CreateDayViewModel(int id, DateTime date, string userId,
                                                      ILaundryRepository laundryRepo, IReservationRepository reservationRepo,
                                                      IUserRepository userRepo)
        {
            var laundries = laundryRepo.GetDormitoryLaundriesWithEntitiesAtDay(id, date) ?? new List <Laundry>();
            var roomId    = userRepo.GetUserById(userId).RoomId;

            var model = new DayViewModel()
            {
                Laundries           = laundries,
                DormitoryId         = id,
                washingMachineState = reservationRepo.GetDormitoryWashingMachineStates(id),
                date = date
            };

            if (roomId != null)
            {
                model.currentRoomReservation = reservationRepo.GetRoomDailyReservation(roomId.Value, date);
                model.hasReservationToRenew  = reservationRepo.HasReservationToRenew(roomId.Value);
            }
            else
            {
                model.currentRoomReservation = null;
                model.hasReservationToRenew  = false;
            }

            return(model);
        }
        public IActionResult SignUpPage()
        {
            //Allows us to access the Day View Model to filter based on appointment time and whether or not the time it taken.
            DayViewModel dayView = new DayViewModel
            {
                Monday = _context.AppointmentTime
                         .Where(x => x.Day == "Monday" && x.Scheduled == false),
                Tuesday = _context.AppointmentTime
                          .Where(x => x.Day == "Tuesday" && x.Scheduled == false),
                Wednesday = _context.AppointmentTime
                            .Where(x => x.Day == "Wednesday" && x.Scheduled == false),
                Thursday = _context.AppointmentTime
                           .Where(x => x.Day == "Thursday" && x.Scheduled == false),
                Friday = _context.AppointmentTime
                         .Where(x => x.Day == "Friday" && x.Scheduled == false),
                Saturday = _context.AppointmentTime
                           .Where(x => x.Day == "Saturday" && x.Scheduled == false),
                Sunday = _context.AppointmentTime
                         .Where(x => x.Day == "Sunday" && x.Scheduled == false)
            };

            //Allows us to still use the Main page model on the view
            return(View(new MainPageModel
            {
                dayViewModel = dayView
            }));
        }
Beispiel #13
0
        //---------------------------------------------------------------------------------//
        public List <DayViewModel> DayView()
        {
            query   = "SELECT * FROM DayTable";
            Command = new SqlCommand(query, Connection);

            List <DayViewModel> dayList = new List <DayViewModel>();

            Connection.Open();

            Reader = Command.ExecuteReader();
            while (Reader.Read())
            {
                DayViewModel days = new DayViewModel();

                days.Id  = Convert.ToInt32(Reader["Id"]);
                days.Day = Reader["Day"].ToString();

                dayList.Add(days);
            }

            Reader.Close();
            Connection.Close();

            return(dayList);
        }
Beispiel #14
0
        protected override void OnAppearing()
        {
            this.viewModel = (DayViewModel)this.BindingContext ?? this.viewModel;

            this.BindingContext = this.viewModel;

            this.CreateGridContent();
        }
Beispiel #15
0
        public async Task <IActionResult> DeleteConfirmed(DayViewModel model)
        {
            var day = await _db.GetAsync <Day>(model.Day.DayId);

            await _db.RemoveAsync(day);

            return(Redirect(model.LastPage));
        }
        private async void listView_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            Day day = e.Item as Day;

            DayViewModel dayViewModel = new DayViewModel(day);

            await Shell.Current.Navigation.PushAsync(new DayViewPage(dayViewModel));
        }
        /// <summary>
        /// Cosntructor for DayPage; initializes properties
        /// </summary>
        public DayPage(Dictionary <string, object> UserData)
        {
            // initialize properties
            this.UserData = UserData;

            // call InitializeComponent() and assign BindingContext
            InitializeComponent();
            BindingContext = new DayViewModel(UserData);
        }
Beispiel #18
0
        private void AddDay(DayViewModel dayViewModel)
        {
            var view = new CalendarDayView
            {
                BindingContext = dayViewModel
            };

            Children.Add(view, dayViewModel.DayPosition.Column, dayViewModel.DayPosition.Row);
        }
        public static string FormatDailyResevations(this HtmlHelper helper, DayViewModel model)
        {
            if (model.Reservations.Count == 1)
            {
                return($"{model.Reservations.Count} { ReservationLabels.SingleReservation }");
            }

            return($"{model.Reservations.Count} { ReservationLabels.MultipleReservations }");
        }
Beispiel #20
0
        private void InitialTileSetup()
        {
            DayViewModel data = ((DayViewModel)this.DataContext);

            if (data != null && data.Highlights != null && data.Highlights.Count > 0)
            {
                LiveTile.UpdateLiveTile(data.Highlights[0].Year, data.Highlights[0].Description);
            }
        }
Beispiel #21
0
        public DayView(DayViewModel viewModel)
        {
            base.MinimumColumnWidth = 390;

            // The items have 10px margins so that they'll have 20px gaps between adjacent, and so we need additional 20px on the right side for the outside of the window
            base.ColumnSpacing = 20;

            ViewModel    = viewModel;
            SelectedDate = viewModel.CurrentDate;
        }
Beispiel #22
0
        public IViewComponentResult Invoke()
        {
            var model = new DayViewModel()
            {
                Duties     = _dutyReposiotory.Duties,
                Categories = _categoryRepository.Categories
            };

            return(View(model));
        }
Beispiel #23
0
        public async Task <IActionResult> Create(DayViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _db.AddDayAsync(model);

                return(Redirect(model.LastPage));
            }
            return(View(model));
        }
Beispiel #24
0
        public IActionResult ShowDate(int year, int month, int day)
        {
            DayViewModel toShow = new DayViewModel();

            toShow.Year      = year;
            toShow.Month     = month;
            toShow.Day       = day;
            toShow.DayEvents = Database.ReadEventsFrom(new DateTime(year, month, day));
            return(View(toShow));
        }
Beispiel #25
0
        public async Task <IActionResult> CreateEvent(DayViewModel model, DateTime date)
        {
            // Can't pass list of Events with form so we have find events again.
            // The rest of DayViewModel is passed with form


            // find users events for given date
            var events = context.Events.Where(a => a.Date == date && a.User.Id == GetCurrentUserId());

            // map events to EventViewModel
            var eventsViewModel = events.Select(a => new EventViewModel
            {
                Id          = a.Id,
                Description = a.Description,
                End         = a.End,
                Start       = a.Start,
                Title       = a.Title
            }).ToList();

            // assign events to model
            model.Events = eventsViewModel;

            if (ModelState.IsValid)
            {
                // Constructs date of the end of the event
                // ( user input is only hours and minutes, rest od DateTime is Now, so we take it from route )
                //
                // if model.End is null then set end of the event to null
                // otherwise take day, month and year from route
                // hours and minutes from user input, and seconds is always 0
                var EndDate = Convert.ToDateTime(model.newEvent.End);

                DateTime?endOfEvent = model.newEvent.End == null ? null : new DateTime?(
                    new DateTime(date.Year, date.Month, date.Day, EndDate.Hour, EndDate.Minute, 0)
                    );

                var userId   = GetCurrentUserId();
                var newEvent = new Event
                {
                    Date        = date,
                    Title       = model.newEvent.Title,
                    Description = model.newEvent.Description,
                    Start       = new DateTime(date.Year, date.Month, date.Day, model.newEvent.Start.Hour, model.newEvent.Start.Minute, 0),
                    End         = endOfEvent,
                    User        = await userManager.FindByIdAsync(userId)
                };

                context.Events.Add(newEvent);
                context.SaveChanges();

                return(RedirectToAction("Day"));
            }
            return(View("Day", model));
        }
        public async Task Create_stores_Day_with_correct_properties()
        {
            var model = new DayViewModel(Day7, "http://completevocaltraining.nl")
            {
                CheckList = new List <CheckedId>()
            };

            await Controller.Create(model);

            Context.Days.FirstOrDefault(x => x.DayId == 7).Should().BeEquivalentTo(Day7);
        }
        public async Task Edit_returns_NotFound_if_Id_changes()
        {
            var d     = Context.Days.FirstOrDefault(x => x.DayId == 1);
            var model = new DayViewModel {
                Day = d, CheckList = new List <CheckedId>()
            };

            var result = await Controller.Edit(8, model);

            result.Should().BeOfType <NotFoundResult>();
        }
Beispiel #28
0
        // Displays items
        public async Task <IActionResult> Index()
        {
            var allDays = await _dayService.GetIncompleteItemsAsync();

            var model = new DayViewModel()
            {
                AllDays = allDays
            };

            return(View(model));
        }
        public async Task Create_stores_new_Day()
        {
            var model = new DayViewModel(Day7, "http://completevocaltraining.nl")
            {
                CheckList = new List <CheckedId>()
            };

            await Controller.Create(model);

            Context.Days.Should().HaveCount(7);
        }
Beispiel #30
0
        public IActionResult Day(int?year, int?month, int?day)
        {
            var          date = new DateTime(year ?? DateTime.Now.Year, month ?? DateTime.Now.Month, day ?? DateTime.Now.Day);
            DayViewModel dm   = new DayViewModel
            {
                header = "Events for " + date.ToString("dd.MM.yyyy"),
                events = EventsAccess.GetEvents(date).OrderBy(e => e.time).ToArray()
            };

            return(View(dm));
        }
        /*
         *
         * private readonly ApplicationDbContext _db;
         * public DOAController(ApplicationDbContext db)
         * {
         *  _db = db;
         * }
         *
         */


        public async Task <IActionResult> Index()
        {
            var myDays = await _dayService.DisplayAllDays();

            // var myDays = await _db.AllDaysFromDb.ToArrayAsync();
            var model = new DayViewModel()
            {
                AllDays = myDays
            };

            return(View(model));
        }