예제 #1
0
        public async Task <ActionResult> ShowGroupTasks(int travelGroupId)
        {
            // we need the travelGroupID to find the current group we are working with.
            var MyHabiticaORM = new habiticatravelEntities();
            var model         = new TravelGroupandUserTaskandItems
            {
                ManyTaskAndItemsList = new List <TaskAndItems>(),
                Users = MyHabiticaORM.TravelGroupUsers.Where(u => u.TravelGroupId == travelGroupId).ToList(),
                TravelGroupandUser = new TravelGroupandUser
                {
                    TravelGroup = MyHabiticaORM.TravelGroups.Find(travelGroupId),
                },
            };
            var tasks = MyHabiticaORM.CustomTasks.Where(ct => ct.TravelGroupId == travelGroupId && ct.UserId == null).ToList();

            foreach (CustomTask task in tasks)
            {
                var tempTaskItems = new TaskAndItems
                {
                    CustomTask = task
                };
                model.ManyTaskAndItemsList.Add(tempTaskItems);
            }

            // going to find the task based on the task id , display all the task info into a view.
            // pk is TaskID , store that task in an object. Store it in a view bag. and send the viewbag to the view


            return(View(model));
        }
예제 #2
0
        public ActionResult UserSearchByEmailForm(int travelGroupID)
        {
            var MyORM         = new habiticatravelEntities();
            var currentUserId = User.Identity.GetUserId();


            // UserGroups viewmodel to pass both TravelGroup and the current username
            var currentTravelGroup = MyORM.TravelGroups.Find(travelGroupID);

            // we need to store a list of TravelGroupandUsers, I modified the viewmodel to also contain user id so we
            // can conditionally render the buttons according to if the user owns the group.

            var model = new TravelGroupandUser()
            {
                TravelGroup = new TravelGroup()
                {
                    Destination   = currentTravelGroup.Destination,
                    GroupLeader   = currentTravelGroup.GroupLeader,
                    TravelGroupId = currentTravelGroup.TravelGroupId,
                    TravelMethod  = currentTravelGroup.TravelMethod
                },
            };

            return(View(model));
        }
예제 #3
0
        public ActionResult SaveNewGroup(TravelGroupVM model)
        {
            var MyORM = new habiticatravelEntities();

            // GroupLeader is related to the Users ID, the ID that exists in Identity
            var userId = User.Identity.GetUserId();

            MyORM.TravelGroups.Add(new TravelGroup()
            {
                Destination     = model.Destination,
                TravelGroupName = model.TravelGroupName,
                TravelMethod    = model.TravelMethod,
                GroupLeader     = userId
            });

            MyORM.SaveChanges();

            var selectedGroup = MyORM.TravelGroups.Where(tg => tg.TravelGroupName == model.TravelGroupName).FirstOrDefault();

            var tUser = new TravelGroupUser
            {
                TravelGroupId  = selectedGroup.TravelGroupId,
                UserId         = userId,
                UserGroupRole  = Convert.ToBoolean((int)GroupRole.Leader),
                UserGroupScore = 0
            };

            MyORM.TravelGroupUsers.Add(tUser);
            MyORM.SaveChanges();

            return(RedirectToAction("ManageMyGroup"));
        }
예제 #4
0
        public async Task <ActionResult> CloneGroupCustomTaskForUsers()
        {
            var travelGroupandUser = (TravelGroupandUser)TempData["travelGroupandUser"];
            var HabiticaORM        = new habiticatravelEntities();
            var travelGroupUsers   = HabiticaORM.TravelGroupUsers.Where(u => u.TravelGroupId == travelGroupandUser.TravelGroup.TravelGroupId).ToList();

            foreach (var user in travelGroupUsers)
            {
                var taskAndItems = (TaskAndItems)TempData["taskAndItems"];
                taskAndItems.CustomTask.UserId = user.UserId;
                var MyHabUser = HabiticaORM.HabiticaUsers.Single(u => u.UserId == user.UserId);
                taskAndItems.CustomTask.TaskTag = MyHabUser.TaskTagId;


                HabiticaORM.TravelGroups.Find(user.TravelGroupId).CustomTasks.Add(taskAndItems.CustomTask);



                HabiticaORM.SaveChanges();

                var TaskConfirm = JObject.FromObject(await HabiticaHTTP.PostNewHabiticaTask(taskAndItems.CustomTask, MyHabUser));

                // assigning the taskId from habitica to the current task we are working with. we are doing this so
                // when we submit this task back to habitica, users will have updated exp and stats.
                taskAndItems.CustomTask.HabiticaTaskId = (string)TaskConfirm["data"]["id"];

                if (taskAndItems.CustomTaskItem != null)
                {
                    foreach (var item in taskAndItems.CustomTaskItem)
                    {
                        // we are adding each checklist item id from habiticas api and storing it in the current
                        // task that we are working with, then we are adding each of those task items into the database
                        // which again contains that checklist id. we are doing this so we can submit this task
                        // back to habitica so we can updat their exp.
                        var ItemConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.PostNewChecklistItem(item, MyHabUser, taskAndItems.CustomTask));
                        List <Checklist> AllChecklistItems = ItemConfirm["data"]["checklist"].ToObject <List <Checklist> >();
                        foreach (Checklist checkItem in AllChecklistItems)
                        {
                            if (checkItem.text == item.ItemName)
                            {
                                item.HabiticaItemId = checkItem.id;
                            }
                        }

                        item.TaskId = taskAndItems.CustomTask.TaskId;
                        HabiticaORM.CustomTaskItems.Add(item);
                    }
                }
                else

                {
                    taskAndItems.CustomTask.CustomTaskItems = new List <CustomTaskItem>();
                }
                HabiticaORM.SaveChanges();
            }
            var route = new RouteValueDictionary(new { controller = "Tasks", action = "ShowGroupTasks", travelGroupId = travelGroupandUser.TravelGroup.TravelGroupId });

            return(RedirectToAction("ShowGroupTasks", route));
        }
예제 #5
0
        public async Task <ActionResult> SubmitTask(int TaskId)
        {
            var HabiticaORM = new habiticatravelEntities();
            var task        = HabiticaORM.CustomTasks.Find(TaskId);
            var data        = (JObject)JObject.FromObject(await HabiticaHTTP.PostScoreATask(task, "up"));

            return(RedirectToAction("Index", "Home"));
        }
예제 #6
0
        public ActionResult UpdateGroup(int TravelGroupId)
        {
            var MyORM = new habiticatravelEntities();

            var model = MyORM.TravelGroups.Find(TravelGroupId);

            return(View(model)); // create a view for this.
        }
예제 #7
0
        public static async Task <JObject> GetUserStats(string id)
        {
            // string CurrentUser = "", CurrentApiToken = "";

            habiticatravelEntities MyHabitica     = new habiticatravelEntities();
            HabiticaUser           MyHabiticaUser = MyHabitica.HabiticaUsers.Where(y => y.UserId == id).FirstOrDefault();

            return(JObject.FromObject(await HabiticaHTTP.GetUserData(MyHabiticaUser)));
        }
예제 #8
0
        // GET: DefaultTasks
        public ActionResult DefaultTasks()
        {
            habiticatravelEntities MyHabitica = new habiticatravelEntities();

            ViewBag.MyTasks     = MyHabitica?.DefaultTasks?.ToList();
            ViewBag.MyTaskItems = MyHabitica?.DefaultTaskItems?.ToList();


            return(View());
        }
예제 #9
0
        public ActionResult DeleteGroupUser(TravelGroupandUser model)
        {
            var MyORM = new habiticatravelEntities();

            TravelGroupUser UserToDelete = MyORM.TravelGroupUsers.Find(model.TravelGroupUser.TravelGroupUsersId);

            MyORM.TravelGroupUsers.Remove(UserToDelete);
            MyORM.SaveChanges();

            return(RedirectToAction("ManageMyGroup"));
        }
예제 #10
0
        public ActionResult AddGroupCustomTask(TravelGroupandUserTaskandItems model)
        {
            var HabiticaORM = new habiticatravelEntities();

            model.TaskAndItems.CustomTask.TravelGroupId = model.TravelGroupandUser.TravelGroup.TravelGroupId;
            HabiticaORM.CustomTasks.Add(model.TaskAndItems.CustomTask);
            HabiticaORM.SaveChanges();

            TempData["taskAndItems"]       = model.TaskAndItems;
            TempData["travelGroupandUser"] = model.TravelGroupandUser;

            return(RedirectToAction("CloneGroupCustomTaskForUsers"));
        }
예제 #11
0
        public async Task <ActionResult> ViewTask(int TaskId)
        {
            var HabiticaORM = new habiticatravelEntities();

            ViewBag.task = HabiticaORM.CustomTasks.Find(TaskId);
            List <CustomTaskItem> MyItemsList = HabiticaORM.CustomTaskItems.Where(t => t.TaskId == TaskId).ToList();
            TaskAndItems          model       = new TaskAndItems();

            model.CustomTask     = HabiticaORM.CustomTasks.Find(TaskId);
            model.CustomTaskItem = MyItemsList;



            return(View(model));
        }
예제 #12
0
        // GET: Group

        public ActionResult ManageMyGroup()
        {
            var MyORM         = new habiticatravelEntities();
            var currentUserId = User.Identity.GetUserId();


            // UserGroups viewmodel to pass both TravelGroup and the current username
            //var currentTravelGroups = MyORM.TravelGroups.Where(g => g.GroupLeader == currentUserId).ToList();
            //replaced the above code to show all groups that the user is a part of

            List <TravelGroup> currentTravelGroups = new List <TravelGroup>();
            List <int>         TravelGroupIds      = MyORM.TravelGroupUsers.Where(u => u.UserId == currentUserId).Select(u => u.TravelGroupId).ToList();

            foreach (int TGId in TravelGroupIds)
            {
                TravelGroup tempGroup = MyORM.TravelGroups.Single(u => u.TravelGroupId == TGId);
                currentTravelGroups.Add(tempGroup);
                //can insert another foreach loop if we need all the users, too
            }

            List <TravelGroupandUser> model = new List <TravelGroupandUser>();

            // we need to store a list of TravelGroupandUsers, I modified the viewmodel to also contain user id so we
            // can conditionally render the buttons according to if the user owns the group.
            foreach (var travelGroup in currentTravelGroups)
            {
                model.Add(new TravelGroupandUser()
                {
                    TravelGroup = new TravelGroup()
                    {
                        TravelGroupName = travelGroup.TravelGroupName,
                        Destination     = travelGroup.Destination,
                        GroupLeader     = travelGroup.GroupLeader,
                        TravelGroupId   = travelGroup.TravelGroupId,
                        TravelMethod    = travelGroup.TravelMethod
                    },
                    UserName = User.Identity.GetUserName(),
                });
            }

            ViewBag.CurrentUser = currentUserId;

            // passing the current UserId so that only the current user will see CRUD
            // operation buttons. ie, the group leader.
            //current user doesn't have to be leader, as if statement in view prevents non-group leader from accessing crud.
            //Updated statements to allow any user to see all groups they are a part of
            return(View(model));
        }
예제 #13
0
        public ActionResult EditCustomTask(int TaskId)

        {
            var HabiticaORM = new habiticatravelEntities();

            var currentTaskItems = new List <CustomTaskItem>(HabiticaORM.CustomTasks.Find(TaskId).CustomTaskItems.ToList());

            CustomTask TaskToEdit = HabiticaORM.CustomTasks.Find(TaskId);

            TaskAndItems TaskAndItemToEdit = new TaskAndItems
            {
                CustomTask     = TaskToEdit,
                CustomTaskItem = currentTaskItems
            };

            return(View(TaskAndItemToEdit)); //TaskAndItemToEdit is sent to EditCustomTask View which returns to SaveCustomTaskChanges
        }
예제 #14
0
        public ActionResult CreateNewGroupCustomTask(int TravelGroupId)
        {
            var MyHabiticaORM = new habiticatravelEntities();
            var MyUsers       = new List <TravelGroupUser>();
            var model         = new TravelGroupandUserTaskandItems()
            {
                Users = MyHabiticaORM.TravelGroupUsers.Where(u => u.TravelGroupId == TravelGroupId).ToList(),
                TravelGroupandUser = new TravelGroupandUser()
                {
                    TravelGroup = MyHabiticaORM.TravelGroups.Find(TravelGroupId),
                },
            };

            // model.TravelGroupandUser.TravelGroup = MyHabitica.TravelGroups.Find(TravelGroupId)

            return(View("GroupCustomTasks", model));
        }
예제 #15
0
        public async Task <ActionResult> RemoveGroupTask(TravelGroupandUserTaskandItems model, int TaskId)
        {
            habiticatravelEntities HabiticaORM  = new habiticatravelEntities();
            CustomTask             selectedTask = HabiticaORM.CustomTasks.Single(t => t.TaskId == TaskId && t.UserId == null);
            var selectedTaskItems = HabiticaORM.CustomTaskItems.Where(t => t.TaskId == TaskId).ToList();

            if (selectedTaskItems.Count != 0)
            {
                foreach (var item in selectedTaskItems)
                {
                    HabiticaORM.CustomTaskItems.Remove(item);
                }
            }
            HabiticaORM.CustomTasks.Remove(selectedTask);


            List <TravelGroupUser> GroupUsers = new List <TravelGroupUser>();

            GroupUsers = HabiticaORM.TravelGroupUsers.Where(u => u.TravelGroupId == model.TravelGroupandUser.TravelGroup.TravelGroupId).ToList();

            foreach (TravelGroupUser user in GroupUsers)
            {
                HabiticaUser MyHabUser             = HabiticaORM.HabiticaUsers.Single(u => u.UserId == user.UserId);
                CustomTask   selectedUserTask      = HabiticaORM.CustomTasks.Single(t => t.TravelGroupId == model.TaskAndItems.CustomTask.TravelGroupId && t.UserId == user.UserId && t.TaskName == model.TaskAndItems.CustomTask.TaskName);
                var          selectedUserTaskItems = HabiticaORM.CustomTaskItems.Where(t => t.TaskId == selectedUserTask.TaskId).ToList();

                if (selectedUserTaskItems.Count != 0)
                {
                    foreach (var item in selectedUserTaskItems)
                    {
                        var ItemConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.DeleteChecklistItem(selectedUserTask, item, MyHabUser));
                        HabiticaORM.CustomTaskItems.Remove(item);
                    }
                }
                var ItemConfirm2 = (JObject)JObject.FromObject(await HabiticaHTTP.DeleteATask(selectedUserTask, MyHabUser));
                HabiticaORM.CustomTasks.Remove(selectedUserTask);
            }

            HabiticaORM.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
예제 #16
0
        public ActionResult DisplayGroupInfo(int TravelGroupId)
        {
            var MyORM = new habiticatravelEntities();

            var DisplayCurrentGroup = MyORM.TravelGroups.Find(TravelGroupId);

            var DisplayCurrentGroupTasks = MyORM.CustomTasks.Where(gt => gt.TravelGroupId == TravelGroupId).ToList();

            var model = new List <TaskAndItems>();

            foreach (var gTask in DisplayCurrentGroupTasks)
            {
                model.Add(new TaskAndItems
                {
                    CustomTask     = gTask,
                    CustomTaskItem = MyORM.CustomTaskItems.Where(ti => ti.TaskId == gTask.TaskId).ToList()
                });
            }
            return(View(model));
        }
예제 #17
0
        public ActionResult EditGroupCustomTask(TravelGroupandUserTaskandItems model, int TaskId)

        {
            habiticatravelEntities HabiticaORM = new habiticatravelEntities();

            var CurrentTaskItems = new List <CustomTaskItem>(HabiticaORM.CustomTasks.Find(TaskId).CustomTaskItems.ToList());

            CustomTask TaskToEdit = HabiticaORM.CustomTasks.Find(TaskId);

            TaskAndItems TaskAndItemToEdit = new TaskAndItems
            {
                CustomTask     = TaskToEdit,
                CustomTaskItem = CurrentTaskItems
            };


            ViewBag.TaskToBeEdited = TaskToEdit;

            return(View(TaskAndItemToEdit));
        }
예제 #18
0
        public ActionResult DeleteGroup(int travelGroupID)
        {
            var MyORM = new habiticatravelEntities();

            var CurrentGroup = MyORM.TravelGroups.Find(travelGroupID);

            List <TravelGroupUser> GroupUsers = MyORM.TravelGroupUsers.Where(gU => gU.TravelGroupId == travelGroupID).ToList();

            if (GroupUsers.Count != 0)
            {
                foreach (var gUser in GroupUsers)
                {
                    MyORM.TravelGroupUsers.Remove(gUser);
                }
            }
            MyORM.TravelGroups.Remove(CurrentGroup);
            MyORM.SaveChanges();


            return(RedirectToAction("ManageMyGroup"));
        }
예제 #19
0
        public ActionResult DisplayGroupScoreboard(int TravelGroupId)
        {
            var MyORM = new habiticatravelEntities();

            var Group = MyORM.TravelGroups.Find(TravelGroupId);

            List <TravelGroupUser>  GroupUsers = Group.TravelGroupUsers.ToList();
            List <GroupUserAndName> model      = new List <GroupUserAndName>();
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            foreach (var user in GroupUsers)
            {
                model.Add(new GroupUserAndName
                {
                    TGUser   = user,
                    UserName = userManager.FindById(user.UserId).UserName
                });
            }

            return(View(model));
        }
예제 #20
0
        public ActionResult AddNewUserToGroup(TravelGroupandUser model) // Adds new user to travel group
        {
            //1. Search user by email or username
            var HabiticaORM = new habiticatravelEntities();

            TravelGroupUser MyTravelGroupUser = new TravelGroupUser()
            {
                UserId         = model.TravelGroupUser.UserId,
                TravelGroupId  = model.TravelGroup.TravelGroupId,
                UserGroupRole  = false,
                UserGroupScore = 0
            };

            //2. Add member to group , we really might not need this.

            HabiticaORM.TravelGroupUsers.Add(MyTravelGroupUser);

            HabiticaORM.SaveChanges();

            //3. Return/Redirect Action to a View
            return(RedirectToAction("ManageMyGroup"));
        }
예제 #21
0
        public async Task <ActionResult> RegisterNewUser()
        {
            // test
            var JSON = (JObject)TempData["JSON"];
            var user = (ApplicationUser)TempData["user"];

            // these are both of our ORM copies, so the the first one is our Habitica User,
            // second ORM is basicaly the an object that wraps around our ApplicationUser, the reason
            // we have to do it this way is because UserManager allows us to preform CRUD operation
            // to our Identity database.
            var HabiticaORM = new habiticatravelEntities();

            userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            // simply finding the user in our Identity database by whatever the user put into
            // the User Name form field.
            var idenUser = userManager.FindByName(user.UserName);

            // creating a new HabiticaUser object which will store the required Non-NULL values, we did
            // not include the data for HabiticaUserID because that will auto increment in the database.
            var habiticaUser = new HabiticaUser
            {
                ApiToken = (string)JSON["data"]["apiToken"],
                Uuid     = (string)JSON["data"]["id"],
                UserId   = idenUser.Id
            };

            var tagKey = (JObject)JObject.FromObject(await HabiticaHTTP.PostCreateTag(habiticaUser));

            habiticaUser.TaskTagId = (string)tagKey["data"]["id"];
            // finishing off our CRUD operation, we are adding the new HabiticaUser into our database
            // and saving our changes so it wil reflect in the database.  then we are simply returning
            // the HomePage view for now.
            HabiticaORM.HabiticaUsers.Add(habiticaUser);
            HabiticaORM.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
예제 #22
0
        public async Task <ActionResult> SaveCustomTaskChanges(TaskAndItems NewTaskAndItems)
        {
            var          HabiticaORM = new habiticatravelEntities();
            string       UserId      = User.Identity.GetUserId();
            HabiticaUser MyHabUser   = HabiticaORM.HabiticaUsers.Single(u => u.UserId == UserId);

            int TaskId = NewTaskAndItems.CustomTask.TaskId;

            CustomTask DBTask = HabiticaORM.CustomTasks.Find(TaskId);

            List <CustomTaskItem> DBItemsList = new List <CustomTaskItem>();

            if (HabiticaORM.CustomTasks.Find(TaskId).CustomTaskItems != null)
            {
                DBItemsList = HabiticaORM.CustomTasks.Find(TaskId).CustomTaskItems.ToList();
            }

            CustomTask            MyTask      = NewTaskAndItems.CustomTask;
            List <CustomTaskItem> MyItemsList = new List <CustomTaskItem>();

            if (NewTaskAndItems.CustomTaskItem != null && DBItemsList.Count != 0)
            {
                foreach (CustomTaskItem T in NewTaskAndItems.CustomTaskItem)
                {
                    MyItemsList.Add(T);
                    HabiticaORM.Entry(HabiticaORM.CustomTaskItems.Find(T.TaskItemsId)).CurrentValues.SetValues(T);
                    var ItemConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.PutUpdateChecklistItem(T, MyHabUser, MyTask));
                }
            }
            MyTask.CustomTaskItems = MyItemsList;
            HabiticaORM.Entry(DBTask).CurrentValues.SetValues(MyTask);
            var ItemConfirm2 = (JObject)JObject.FromObject(await HabiticaHTTP.PutUpdateTask(MyTask, MyHabUser));

            HabiticaORM.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
예제 #23
0
        public ActionResult DisplaySelectedGroup(int TravelGroupId)
        {
            var MyORM = new habiticatravelEntities();

            var CurrentGroup = MyORM.TravelGroups.Find(TravelGroupId);

            var currentTravelGroupUser = MyORM.TravelGroupUsers.Where(cu => cu.TravelGroupId == TravelGroupId).ToList();

            List <TravelGroupandUser> model = new List <TravelGroupandUser>();

            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            foreach (var user in currentTravelGroupUser)
            {
                model.Add(new TravelGroupandUser
                {
                    UserName = userManager.FindById(user.UserId).UserName
                });
            }

            ViewBag.Group = CurrentGroup.TravelGroupName;

            return(View(model));
        }
예제 #24
0
        public async Task <ActionResult> RemoveTask(int TaskId)
        {
            var          HabiticaORM = new habiticatravelEntities();
            string       UserId      = User.Identity.GetUserId();
            HabiticaUser MyHabUser   = HabiticaORM.HabiticaUsers.Single(u => u.UserId == UserId);

            var selectedTask      = HabiticaORM.CustomTasks.Where(t => t.TaskId == TaskId).FirstOrDefault();
            var selectedTaskItems = HabiticaORM.CustomTaskItems.Where(t => t.TaskId == TaskId).ToList();

            if (selectedTaskItems.Count != 0)
            {
                foreach (var item in selectedTaskItems)
                {
                    var ItemConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.DeleteChecklistItem(selectedTask, item, MyHabUser));
                    HabiticaORM.CustomTaskItems.Remove(item);
                }
            }
            var ItemConfirm2 = (JObject)JObject.FromObject(await HabiticaHTTP.DeleteATask(selectedTask, MyHabUser));

            HabiticaORM.CustomTasks.Remove(selectedTask);
            HabiticaORM.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
예제 #25
0
        public ActionResult SaveUpdatedGroupChanges(TravelGroup model)
        {
            var    MyORM         = new habiticatravelEntities();
            string currentUserId = User.Identity.GetUserId();

            int TravelGroupId = model.TravelGroupId;

            if (!ModelState.IsValid)
            {
                return(View("../Shared/Error"));
            }

            var MyDBGroup = MyORM.TravelGroups.Find(model.TravelGroupId);

            MyORM.Entry(MyDBGroup).CurrentValues.SetValues(model);

            MyORM.SaveChanges();


            List <TravelGroupandUser> model2 = new List <TravelGroupandUser>();

            List <int> TravelGroupIds = MyORM.TravelGroupUsers.Where(u => u.UserId == currentUserId).Select(u => u.TravelGroupId).ToList();

            foreach (int TGId in TravelGroupIds)
            {
                TravelGroup        tempGroup = MyORM.TravelGroups.Single(u => u.TravelGroupId == TGId);
                TravelGroupandUser tempTGU   = new TravelGroupandUser
                {
                    TravelGroup = tempGroup
                };
                //can insert another foreach loop if we need the users, too
                model2.Add(tempTGU);
            }

            return(View("ManageMyGroup", model2));
        }
예제 #26
0
        public async Task <ActionResult> DisplayStats()
        {
            if (User.Identity.IsAuthenticated)
            {
            }
            var userId = User.Identity.GetUserId();
            var data   = await HabiticaUtil.GetUserStats(userId);

            data = (JObject)data["data"];

            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                userStats = new UserStat
                {
                    UserId               = userId,
                    UserStatsPer         = (int)data["stats"]["per"],
                    UserStats_int        = (int)data["stats"]["int"],
                    UserStatsCon         = (int)data["stats"]["con"],
                    UserStatsStr         = (int)data["stats"]["str"],
                    UserStatsPoints      = (int)data["stats"]["points"],
                    UserStats_class      = data["stats"]["class"].ToString(),
                    UserStatsLvl         = (int)data["stats"]["lvl"],
                    UserStatsGp          = (int)data["stats"]["gp"],
                    UserStatsExp         = (int)data["stats"]["exp"],
                    UserStatsMp          = (int)data["stats"]["mp"],
                    UserStatsHp          = (int)data["stats"]["hp"],
                    UserStatsToNextLevel = (int)data["stats"]["toNextLevel"],
                    UserStatsMaxHealth   = (int)data["stats"]["maxHealth"],
                    UserStatsMaxMP       = (int)data["stats"]["maxMP"],
                    TrainingCon          = (int)data["stats"]["training"]["con"],
                    TrainingStr          = (int)data["stats"]["training"]["str"],
                    TrainingPer          = (int)data["stats"]["training"]["per"],
                    Training_int         = (int)data["stats"]["training"]["int"],
                    BuffsSeafoam         = (bool)data["stats"]["buffs"]["seafoam"],
                    BuffsShinySeed       = (bool)data["stats"]["buffs"]["shinySeed"],
                    BuffsSpookySparkles  = (bool)data["stats"]["buffs"]["spookySparkles"],
                    BuffsSnowball        = (bool)data["stats"]["buffs"]["snowball"],
                    BuffsStreaks         = (bool)data["stats"]["buffs"]["streaks"],
                    BuffsStealth         = (int)data["stats"]["buffs"]["stealth"],
                    BuffsCon             = (int)data["stats"]["buffs"]["con"],
                    BuffsPer             = (int)data["stats"]["buffs"]["per"],
                    Buffs_int            = (int)data["stats"]["buffs"]["int"],
                    BuffsStr             = (int)data["stats"]["buffs"]["str"],
                    ProfileName          = data["profile"]["name"].ToString()
                };
                if (data["profile"].Contains("imageUrl"))
                {
                    userStats.ProfilePhoto = data["profile"]["imageUrl"].ToString();
                }
                if (data["profile"].Contains("blurb"))
                {
                    userStats.ProfileBlurb = data["profile"]["blurb"].ToString();
                }

                habiticatravelEntities orm   = new habiticatravelEntities();
                List <CustomTask>      Tasks = orm.CustomTasks.Where(t => t.UserId == userId).ToList();

                var taskDates       = Tasks.Select(t => t.ReminderTime).ToList();
                var reminderEndTime = new List <DateTime>();

                ViewBag.Tasks = Tasks;
                return(View("index", userStats));
            }
        }
예제 #27
0
        public async Task <ActionResult> SaveCustomGroupTaskChanges(TaskAndItems NewTaskAndItems)
        {
            habiticatravelEntities HabiticaORM = new habiticatravelEntities();

            int TaskId = NewTaskAndItems.CustomTask.TaskId;

            CustomTask DBTask = HabiticaORM.CustomTasks.Find(TaskId);

            List <CustomTaskItem> DBItemsList = new List <CustomTaskItem>();

            if (DBTask.CustomTaskItems != null)
            {
                DBItemsList = HabiticaORM.CustomTasks.Find(TaskId).CustomTaskItems.ToList();
            }

            CustomTask            MyTask      = NewTaskAndItems.CustomTask;
            List <CustomTaskItem> MyItemsList = new List <CustomTaskItem>();

            if (NewTaskAndItems.CustomTaskItem != null && DBItemsList.Count != 0)
            {
                foreach (CustomTaskItem T in NewTaskAndItems.CustomTaskItem)
                {
                    MyItemsList.Add(T);
                    HabiticaORM.Entry(HabiticaORM.CustomTaskItems.Find(T.TaskItemsId)).CurrentValues.SetValues(T);
                }
            }
            MyTask.CustomTaskItems = MyItemsList;
            HabiticaORM.Entry(DBTask).CurrentValues.SetValues(MyTask);
            HabiticaORM.SaveChanges();

            //Above changes the Group Item only. Below we change the values for each Group Member


            List <TravelGroupUser> GroupUsers = new List <TravelGroupUser>();

            GroupUsers = HabiticaORM.TravelGroupUsers.Where(u => u.TravelGroupId == NewTaskAndItems.CustomTask.TravelGroupId).ToList();

            foreach (TravelGroupUser user in GroupUsers)
            {
                HabiticaUser MyHabUser = HabiticaORM.HabiticaUsers.Single(u => u.UserId == user.UserId);
                CustomTask   UserTask  = HabiticaORM.CustomTasks.Single(u => u.TravelGroupId == NewTaskAndItems.CustomTask.TravelGroupId && u.UserId == user.UserId && u.TaskName == DBTask.TaskName);

                List <CustomTaskItem> UserItemsList = new List <CustomTaskItem>();
                if (UserTask.CustomTaskItems != null)
                {
                    UserItemsList = HabiticaORM.CustomTasks.Find(UserTask.TaskId).CustomTaskItems.ToList();
                }

                CustomTask            MyUserTask      = NewTaskAndItems.CustomTask;
                List <CustomTaskItem> MyUserItemsList = new List <CustomTaskItem>();

                if (NewTaskAndItems.CustomTaskItem != null && DBItemsList.Count != 0)
                {
                    foreach (CustomTaskItem T in NewTaskAndItems.CustomTaskItem)
                    {
                        MyUserItemsList.Add(T);
                        HabiticaORM.Entry(HabiticaORM.CustomTaskItems.Find(T.TaskItemsId)).CurrentValues.SetValues(T);
                        var ItemConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.PutUpdateChecklistItem(T, MyHabUser, MyTask));
                    }
                }
                MyUserTask.CustomTaskItems = MyUserItemsList;
                HabiticaORM.Entry(UserTask).CurrentValues.SetValues(MyUserTask);
                var ItemConfirm2 = (JObject)JObject.FromObject(await HabiticaHTTP.PutUpdateTask(MyTask, MyHabUser));
                HabiticaORM.SaveChanges();
            }

            return(RedirectToAction("Index", "Home"));
        }
예제 #28
0
        public async Task <ActionResult> AddCustomTask(TaskAndItems model)
        {
            string userId      = User.Identity.GetUserId();
            var    HabiticaORM = new habiticatravelEntities();
            List <CustomTaskItem> items;

            if (model.CustomTaskItem != null)
            {
                items = model.CustomTaskItem;
                HabiticaORM.CustomTaskItems.AddRange(items);
            }
            else
            {
                items = new List <CustomTaskItem> {
                    new CustomTaskItem()
                };
                HabiticaORM.CustomTaskItems.AddRange(items);
            }


            model.CustomTask.UserId = userId;
            HabiticaUser MyHabUser = HabiticaORM.HabiticaUsers.Single(u => u.UserId == userId);

            model.CustomTask.TaskTag  = MyHabUser.TaskTagId;
            model.CustomTask.TaskType = "todo";
            model.CustomTaskItem      = items;
            var TaskConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.PostNewHabiticaTask(model.CustomTask, MyHabUser));

            HabiticaORM.CustomTasks.Add(model.CustomTask);

            try
            {
                HabiticaORM.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }

            var currentTask = HabiticaORM.CustomTasks.Where(t => model.CustomTask.TaskId == t.TaskId).FirstOrDefault();
            var TestItem    = (string)TaskConfirm["data"]["id"];

            currentTask.HabiticaTaskId = (string)TaskConfirm["data"]["id"];
            string habtaskid = currentTask.HabiticaTaskId;

            HabiticaORM.SaveChanges();

            if (model.CustomTask.CustomTaskItems.Count != 0)
            {
                var taskItems = model.CustomTaskItem.ToList();
                foreach (var item in taskItems)
                {
                    var ItemConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.PostNewChecklistItem(item, MyHabUser, currentTask));
                    List <Checklist> AllChecklistItems = ItemConfirm["data"]["checklist"].ToObject <List <Checklist> >();
                    foreach (Checklist list in AllChecklistItems)
                    {
                        if (list.text == item.ItemName)
                        {
                            item.HabiticaItemId = list.id;
                        }
                    }

                    item.TaskId = currentTask.TaskId;
                }
                currentTask.CustomTaskItems = taskItems;
            }
            else

            {
                currentTask.CustomTaskItems = new List <CustomTaskItem>();
            }


            HabiticaORM.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
예제 #29
0
        public ActionResult CloneTask(int TaskId)
        {
            habiticatravelEntities MyHabitica  = new habiticatravelEntities();
            DefaultTask            TaskToClone = MyHabitica.DefaultTasks.Find(TaskId);
            string       userId    = User.Identity.GetUserId();
            HabiticaUser MyHabUser = MyHabitica.HabiticaUsers.Single(u => u.UserId == userId);

            CustomTask ClonedTask = new CustomTask
            {
                TaskName          = TaskToClone.TaskName,
                TaskType          = TaskToClone.TaskType,
                TaskTag           = MyHabUser.TaskTagId,
                TaskNotes         = TaskToClone.TaskNotes,
                TaskDueDate       = TaskToClone.TaskDueDate,
                TaskDifficulty    = TaskToClone.TaskDifficulty,
                ReminderStartDate = TaskToClone.ReminderStartDate,
                ReminderTime      = TaskToClone.ReminderTime,
                UserId            = userId,
                CustomTaskItems   = new List <CustomTaskItem>()
            };

            MyHabitica.CustomTasks.Add(ClonedTask);
            try
            {
                MyHabitica.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }

            List <DefaultTaskItem> CloneItemsList = new List <DefaultTaskItem>(MyHabitica.DefaultTasks.Find(TaskId).DefaultTaskItems.ToList());
            List <CustomTaskItem>  NewItemsList   = new List <CustomTaskItem>();

            for (int i = 0; i < CloneItemsList.Count; i++)
            {
                var        TempItem = new CustomTaskItem();
                int        TempId   = ClonedTask.TaskId;
                CustomTask TempTask = MyHabitica.CustomTasks.Find(TempId);
                TempItem.ItemName = CloneItemsList[i].ItemName;
                TempItem.TaskId   = TempTask.TaskId;

                MyHabitica.CustomTaskItems.Add(TempItem);
                ClonedTask.CustomTaskItems.Add(TempItem);
            }

            try
            {
                MyHabitica.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }

            return(RedirectToAction("Index", "Home"));
        }
예제 #30
0
        public async Task <ActionResult> HabiticaLoginHandler(RegisterViewModel model)
        {
            var JSON = (JObject)JObject.FromObject(await HabiticaHTTP.PostUserLogin(model.Email, model.Password));

            if (bool.Parse(JSON["success"].ToString()))
            {
                var UpdatedHabiticaUser = new HabiticaUser
                {
                    Uuid     = (string)JSON["data"]["id"],
                    ApiToken = (string)JSON["data"]["apiToken"],
                };

                var HabiticaORM = new habiticatravelEntities();
                userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

                // This is for two purposes, if this returns null, than we make a new user,
                // if it does not, we will find this user in the Habitica table by ID.
                ApplicationUser User = userManager.FindByEmail(model.Email);
                if (User == null)
                {
                    var user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        var newUser = userManager.FindByEmail(user.Email);
                        UpdatedHabiticaUser.UserId = newUser.Id;

                        // pulling user data so we can check if that user has the HabiticaAbroad tag, reason we care
                        // is we do not want to create duplicate tags on their habitica account.
                        var        userData = (JObject)JObject.FromObject(await HabiticaHTTP.GetUserData(UpdatedHabiticaUser));
                        List <Tag> tags     = userData["data"]["tags"].ToObject <List <Tag> >();
                        // var isTagged = tags.Where(t => t.id == "Habitica Abroad");
                        var tagKey = JObject.FromObject(await HabiticaHTTP.PostCreateTag(UpdatedHabiticaUser));
                        UpdatedHabiticaUser.TaskTagId = (string)tagKey["data"]["id"];
                        HabiticaORM.HabiticaUsers.Add(UpdatedHabiticaUser);
                        HabiticaORM.SaveChanges();
                        return(RedirectToAction("Index", "Home"));
                    }
                    AddErrors(result);

                    return(View(model));
                }
                else
                {
                    // simply updating the habitica User that is not null with the
                    // HabiticaUser object that was created on line 88
                    var result = await SignInManager.PasswordSignInAsync(User.UserName, model.Password, false, shouldLockout : false);

                    switch (result)
                    {
                    case SignInStatus.Success:
                        return(RedirectToAction("Index", "Home"));

                    case SignInStatus.Failure:
                    default:
                        ModelState.AddModelError("", "Invalid login attempt.");
                        return(View(model));
                    }
                }
            }
            else
            {
                // this is just a place holder, we need to pass a view that tells user
                // that
                ViewBag.Message = "You do not have an account with Habitica. Please Register.";
                return(View("../HabiticaAccount/AlreadyRegisteredWithHabitica"));
            }
        }