Esempio n. 1
0
        public EditOrDeleteGoalDefWindow(GoalDefinition goalDefinition, User user)
        {
            InitializeComponent();
            var vm = new EditOrDeleteGoalDefViewModel(goalDefinition, user);

            this.DataContext     = vm;
            vm.CloseWindowEvent += Vm_CloseWindowEvent;
        }
Esempio n. 2
0
        public AddGoalRecordWindow(User user, GoalDefinition goalDefinition, DateTime date)
        {
            InitializeComponent();
            var vm = new AddGoalRecordViewModel(user, goalDefinition, date);

            this.DataContext     = vm;
            vm.CloseWindowEvent += Vw_CloseWindowEvent;
        }
Esempio n. 3
0
        public AddGoalRecordViewModel(User user, GoalDefinition goalDefinition, DateTime dateTime)
        {
            SelectedDate       = dateTime;
            ActivityBtnMessage = "Add activity";
            using (var db = new GoalMasterDatabaseContext())
            {
                var goalDef = db.GoalDefinitions.FirstOrDefault(
                    x => x.ID == goalDefinition.ID);
                existingGoalRecord = db.GoalRecords.FirstOrDefault(x => x.Date == SelectedDate &&
                                                                   x.GoalDefinition.ID == goalDefinition.ID &&
                                                                   x.User.ID == user.ID);
                if (existingGoalRecord != null)
                {
                    isInEditMode       = true;
                    ActivityBtnMessage = "Edit activity";
                    editModeValue      = existingGoalRecord.Value;
                    Note = existingGoalRecord.Note;
                }
                GoalDefinition          = goalDef;
                GoalDefinition.GoalType = goalDef.GoalType;
            }

            User = user;

            AddNewGoalRecordCommand = new RelayCommand(AddNewGoalRecord);
            DeleteGoalRecordCommand = new RelayCommand(DeleteGoalRecord);

            _goalTypeID = GoalDefinition.GoalType.ID;

            if (GoalDefinition.GoalType.ID == 1)//DoneOrNotDone
            {
                VisibilityValueBox = Visibility.Hidden;
                VisibilityBoolBox  = Visibility.Visible;

                TrueFalseOptions = new ObservableCollection <BoolHelper>();
                TrueFalseOptions.Add(new BoolHelper(true, "Done"));
                TrueFalseOptions.Add(new BoolHelper(false, "Not done"));
                if (isInEditMode)
                {
                    TrueOption = TrueFalseOptions.FirstOrDefault(x => x.Value == Convert.ToBoolean(editModeValue));//editModeValue ? 1 : 0;
                }
                else
                {
                    TrueOption = TrueFalseOptions.First();
                }
            }
            else//Numeric values
            {
                VisibilityValueBox = Visibility.Visible;
                VisibilityBoolBox  = Visibility.Hidden;
                if (isInEditMode)
                {
                    _value = editModeValue.ToString();
                }
            }
        }
Esempio n. 4
0
        private void AddNewGoal()
        {
            //todo Zrobić dodawanie do goalDefinitions zaproszonych userów us.GoalDefinitions.Add///
            GoalDefinition goalDefinition = new GoalDefinition();

            if (InvitedFriends.Count == 0)
            {
                goalDefinition.Shared = false;
            }
            else
            {
                goalDefinition.Shared = true;
            }

            goalDefinition.Name        = Name;
            goalDefinition.Description = Description;

            using (var db = new GoalMasterDatabaseContext())
            {
                var gt = db.GoalTypes.FirstOrDefault(x => x.ID == FirstGoalType.ID);
                var us = db.Users.FirstOrDefault(x => x.ID == User.ID);
                //Important
                db.GoalDefinitions.Add(goalDefinition);
                db.SaveChanges();
                goalDefinition.OwnerUserID = us;
                goalDefinition.GoalType    = gt;
                goalDefinition.Users.Add(us);


                //friends  todo!

                //us.GoalDefinitions.Add(goalDefinition);
                //db.SaveChanges();
                foreach (var invitedFriend in InvitedFriends)
                {
                    var friend = db.Users.FirstOrDefault(x => x.ID == invitedFriend.ID);
                    goalDefinition.Users.Add(friend);
                    //var goalDef = new GoalDefinition();
                    //friend.GoalDefinitions.Add(goalDef);
                    //goalDef = goalDefinition;
                    //friend.GoalDefinitions.Add(goalDefinition); //dodaje tylko do ostatniego usera

                    //db.SaveChanges();
                }
                db.SaveChanges();
            }
            if (CloseWindowEvent != null)
            {
                CloseWindowEvent(this, null);
            }
        }
Esempio n. 5
0
        public EditOrDeleteGoalDefViewModel(GoalDefinition goalDefinition, User user)
        {
            DeleteGoalCommand   = new RelayCommand(DeleteGoal);
            EditGoalCommand     = new RelayCommand(EditGoal);
            RemoveFriendCommand = new RelayCommand(RemoveFriend);
            AddFriendCommand    = new RelayCommand(AddFriend);

            Friends        = new ObservableCollection <User>();
            InvitedFriends = new ObservableCollection <User>();

            User = user;

            using (var db = new GoalMasterDatabaseContext())
            {
                var goalDef = db.GoalDefinitions.FirstOrDefault(gd => gd.ID == goalDefinition.ID);
                _goalDefinition = goalDef;
                Name            = goalDef.Name;
                Description     = goalDef.Description;

                if (goalDef.OwnerUserID.ID == user.ID)
                {
                    IsOwner = true;
                    DelOrUnsubscribeMessage = "Delete goal";
                }
                else
                {
                    IsOwner = false;
                    DelOrUnsubscribeMessage = "Unsubscribe from goal";
                    Info = "Only goal owner can edit invited friends";
                }
            }

            refreshListsOfFriends();
            SelectedFriend        = Friends.FirstOrDefault();
            SelectedInvitedFriend = InvitedFriends.FirstOrDefault();
        }