Ejemplo n.º 1
0
        public List <ProMaUser> GetUsersNotAssignedToChore([FromForm] int choreId)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                ProMaUser user = DataController.LoggedInUser;

                if (user == null)
                {
                    throw new NotLoggedInException();
                }

                // get each shared chore membership for this chore
                List <SharedChoreMembership> memberships = SharedChoreMembershipHandler.GetSharedChoreMembershipsForChore(choreId);

                return(FriendshipHandler.GetUserFriends(user.UserId).Where(x => !memberships.Any(y => y.UserId == x.UserId)).ToList());
            }
        }
Ejemplo n.º 2
0
        public ProMaUser RegisterProMaUser([FromBody] RegisterProMaUserRequestObject requestObject)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                if (string.IsNullOrWhiteSpace(requestObject.md5Password))
                {
                    throw new Exception("Invalid password");
                }

                if (!ProMaUser.VerifyName(requestObject.userName))
                {
                    throw new Exception("Invalid user name");
                }

                // make sure no user with the same name
                ProMaUser existingUser = ProMaUserHandler.GetUserByUserName(requestObject.userName);

                if (existingUser != null)
                {
                    throw new Exception("User already exists by that name");
                }

                ProMaUser newUser = new ProMaUser();

                newUser.HashedPassword = ProMaUser.ComputeSHA256(requestObject.md5Password);;
                newUser.JoinTime       = ProMaUser.NowTime();
                newUser.UserName       = requestObject.userName;

                ProMaUserHandler.AddProMaUser(newUser);

                PostedNote seedNote = new PostedNote();
                seedNote.UserId        = newUser.UserId;
                seedNote.NoteText      = @"You can create new notes by using the text area in the right.\r\n\r\nNotes can have note types (see the ""as type"" selector). You can create new note types using the utilties area to the bottom right, and selecting the ""Note Types"" tab.\r\n\r\nYou can sort by note types using the filters at the bottom of the screen, among other filter options.\r\n\r\nEach note has buttons to the top right of them, like the pencil icon for editing a note or the target icon for marking it as complete. Use these to alter the notes however you would like.\r\n\r\nTry out the other tabs for useful utilities, like keeping track of daily chores, or the Egg Timer tab to handle productivity cycles.\r\n\r\nHave fun using ProMa!";
                seedNote.PostedTime    = ProMaUser.NowTime();
                seedNote.Active        = true;
                seedNote.Completed     = false;
                seedNote.CompletedTime = null;
                seedNote.Highlighted   = false;
                seedNote.NoteTypeId    = null;

                PostedNoteHandler.AddPostedNote(seedNote);

                return(newUser);
            }
        }
Ejemplo n.º 3
0
        public void ChangeChoreItemCompletion([FromBody] ChangeChoreItemCompletionRequestObject requestObject)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                ProMaUser user = DataController.LoggedInUser;

                if (user == null)
                {
                    throw new NotLoggedInException();
                }

                DateTime dayForRequest = new DateTime(requestObject.year, requestObject.month, requestObject.day).Date;

                if (requestObject.completed)
                {
                    CompletedChoreHandler.CompleteChore(requestObject.choreId, dayForRequest, user.UserId);
                }
                else
                {
                    CompletedChoreHandler.UnCompleteChore(requestObject.choreId, dayForRequest);
                }
            }
        }
Ejemplo n.º 4
0
        public string MarkovPostedNote([FromForm] int noteTypeId)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            Dictionary <string, List <string> > MarkovTree = new Dictionary <string, List <string> >();

            MarkovTree.Add("_start", new List <string>());
            MarkovTree.Add("_end", new List <string>());

            List <string> notes = new List <string>();

            using (ProMaDB scope = new ProMaDB())
            {
                notes = scope.PostedNotes.Where(x => (x.NoteTypeId == noteTypeId || noteTypeId == -1) && x.UserId == user.UserId).Where(x => x.Active == true).Select(x => x.NoteText).ToList();
            }

            foreach (string curNote in notes)
            {
                AddPhraseToMarkovChain(curNote, MarkovTree);
            }

            if (MarkovTree["_start"].Count() == 0)
            {
                return("(no notes?)");
            }

            string phrase = "";

            Random rand     = new Random();
            string nextWord = MarkovTree["_start"][rand.Next(MarkovTree["_start"].Count())];

            phrase += UpperCaseFirstLetter(nextWord);

            if (MarkovTree.ContainsKey(nextWord))
            {
                phrase += " ";
            }

            while (MarkovTree.ContainsKey(nextWord))
            {
                string dictionaryKey = GetDictionaryKeyForWord(nextWord);

                nextWord = MarkovTree[dictionaryKey][rand.Next(MarkovTree[nextWord].Count())];

                string useThisWord = nextWord;

                phrase += useThisWord;

                if (MarkovTree.ContainsKey(nextWord))
                {
                    phrase += " ";
                }
            }

            return(phrase);
        }