private async void AddItem(TaskOrEventType type)
        {
            if (MainScreenViewModel.Classes == null || MainScreenViewModel.Classes.Count == 0)
            {
                await new PortableMessageDialog("You don't have any classes. Make sure you've opened a semester that has classes.", "No classes").ShowAsync();
                return;
            }

            MainScreenViewModel.ShowPopup(AddTaskOrEventViewModel.CreateForAdd(MainScreenViewModel, new AddTaskOrEventViewModel.AddParameter()
            {
                SemesterIdentifier = MainScreenViewModel.CurrentSemesterId,
                Classes            = MainScreenViewModel.Classes,
                SelectedClass      = null,
                Type    = type,
                DueDate = DateTime.Today
            }));

            RemoveViewModel();
        }
Exemplo n.º 2
0
        public static AddTaskOrEventViewModel CreateForEdit(BaseViewModel parent, EditParameter editParams)
        {
            var account = parent.FindAncestor <MainWindowViewModel>()?.CurrentAccount;

            if (account == null)
            {
                throw new NullReferenceException("CurrentAccount was null");
            }
            ViewItemClass   c    = editParams.Item.Class;
            TaskOrEventType type = editParams.Item.Type;

            if (c == null)
            {
                throw new NullReferenceException("Class of the item was null. Item id " + editParams.Item.Identifier);
            }

            if (c.Semester == null)
            {
                throw new NullReferenceException("Semester of the class was null. Item id " + editParams.Item.Identifier);
            }

            if (c.Semester.Classes == null)
            {
                throw new NullReferenceException("Classes of the semester was null. Item id " + editParams.Item.Identifier);
            }

            var model = new AddTaskOrEventViewModel(parent)
            {
                Account               = account,
                State                 = OperationState.Editing,
                EditParams            = editParams,
                Name                  = editParams.Item.Name,
                Classes               = GetClassesWithNoClassClass(c.Semester.Classes),
                Date                  = editParams.Item.DateInSchoolTime.Date,
                Details               = editParams.Item.Details,
                Type                  = type,
                ImageNames            = editParams.Item.ImageNames.ToArray(),
                IsInDifferentTimeZone = parent.FindAncestorOrSelf <MainScreenViewModel>().CurrentAccount.IsInDifferentTimeZone,
                Class                 = c // Assign class last, since it also assigns weight categories
            };

            // Assign existing image attachments
            model.ImageAttachments = new ObservableCollection <BaseEditingImageAttachmentViewModel>(editParams.Item.ImageNames.Select(i => new EditingExistingImageAttachmentViewModel(model, i)));

            switch (editParams.Item.GetActualTimeOption())
            {
            case DataItemMegaItem.TimeOptions.AllDay:
                model.SelectedTimeOption = model.TimeOption_AllDay;
                break;

            case DataItemMegaItem.TimeOptions.BeforeClass:
                model.SelectedTimeOption = model.TimeOption_BeforeClass;
                break;

            case DataItemMegaItem.TimeOptions.Custom:
                model._startTime         = new TimeSpan(editParams.Item.DateInSchoolTime.Hour, editParams.Item.DateInSchoolTime.Minute, 0);
                model._endTime           = editParams.Item.EndTimeInSchoolTime.TimeOfDay;
                model.SelectedTimeOption = model.TimeOption_Custom;
                break;

            case DataItemMegaItem.TimeOptions.DuringClass:
                model.SelectedTimeOption = model.TimeOption_DuringClass;
                break;

            case DataItemMegaItem.TimeOptions.EndOfClass:
                model.SelectedTimeOption = model.TimeOption_EndOfClass;
                break;

            case DataItemMegaItem.TimeOptions.StartOfClass:
                model.SelectedTimeOption = model.TimeOption_StartOfClass;
                break;
            }

            // We don't want to consider setting the initial time option as the user configuring the time option
            model._userChangedSelectedTimeOption = false;

            return(model);
        }