public async Task <IActionResult> MyPosts(string userId)
        {
            ViewBag.ActivePage = "MyPosts";

            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Home"));
            }

            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            CustomUser customUserFromDb = await _userManager.FindByIdAsync(userId);

            if (currentUser == customUserFromDb)
            {
                ViewBag.AuthorOfPosts = 1;
            }

            ViewBag.CurrentUser = currentUser.Id;

            MyPostsVM myPostsVM = new MyPostsVM
            {
                Posts = customUserFromDb.Posts.Where(po => po.IsDeleted == false).OrderByDescending(p => p.UpdatedAtTime > p.CreatedAtTime ? p.UpdatedAtTime : p.CreatedAtTime)
            };

            return(View(myPostsVM));
        }
        public async Task <IActionResult> DeletePost(int?id)
        {
            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            if (id == null)
            {
                return(NotFound());
            }

            Post post = await _context.Posts.FindAsync(id);

            if (post == null)
            {
                return(NotFound());
            }

            if (currentUser != post.CustomUser)
            {
                return(NotFound());
            }

            post.IsDeleted     = true;
            post.DeletedAtTime = DateTime.Now;
            await _context.SaveChangesAsync();

            return(Json(new { success = 200 }));
        }
        public async Task <IActionResult> UpdatePost(int?id)
        {
            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            ViewBag.CurrentUser = currentUser.Id;

            if (id == null)
            {
                return(NotFound());
            }

            Post post = await _context.Posts.FindAsync(id);

            if (post == null)
            {
                return(NotFound());
            }

            if (currentUser != post.CustomUser)
            {
                return(NotFound());
            }

            return(View(post));
        }
        public async Task <IActionResult> UpdatePost(int?id, Post inputPost)
        {
            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            if (id == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("MyPosts", "Profile", new { userId = currentUser.Id }));
            }

            Post post = await _context.Posts.FindAsync(id);

            if (post == null)
            {
                return(NotFound());
            }

            if (currentUser != post.CustomUser)
            {
                return(NotFound());
            }

            post.PostContent   = inputPost.PostContent.Trim();
            post.IsUpdated     = true;
            post.UpdatedAtTime = DateTime.Now;
            await _context.SaveChangesAsync();

            return(RedirectToAction("MyPosts", "Profile", new { userId = currentUser.Id }));
        }
        public async Task <IActionResult> ExploreNewUsers()
        {
            ViewBag.ActivePage = "ExploreNewUsers";

            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            ViewBag.CurrentUser = currentUser.Id;

            IQueryable <ConnectedUser> myFollowingUsers    = _context.ConnectedUsers.Where(cu => cu.FollowedById == currentUser.Id);
            List <CustomUser>          filteredCustomUsers = new List <CustomUser>();
            CustomUser duplicateUser = null;

            foreach (CustomUser customUser in _userManager.Users)
            {
                if (myFollowingUsers.Count() > 0 && customUser.Id != currentUser.Id)
                {
                    foreach (ConnectedUser myFollowingUser in myFollowingUsers)
                    {
                        if (customUser.Id != myFollowingUser.FollowingId)
                        {
                            filteredCustomUsers.Add(customUser);
                            duplicateUser = customUser;
                            //break;
                        }
                        else
                        {
                            if (duplicateUser == customUser)
                            {
                                filteredCustomUsers.Remove(duplicateUser);
                            }
                            break;
                        }
                    }
                }
                else if (myFollowingUsers.Count() == 0 && customUser.Id != currentUser.Id)
                {
                    filteredCustomUsers.Add(customUser);
                }
            }

            for (int i = 0; i < filteredCustomUsers.Count(); i++)
            {
                if (i != filteredCustomUsers.Count())
                {
                    if (filteredCustomUsers.ElementAt(i) == filteredCustomUsers.ElementAt(i + 1))
                    {
                        filteredCustomUsers.Remove(filteredCustomUsers.ElementAt(i));
                    }
                }
            }

            FollowVM followVM = new FollowVM
            {
                FilteredCustomUsers = filteredCustomUsers
            };

            return(View(followVM));
        }
        public async Task <IActionResult> ChangePassword()
        {
            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            ViewBag.CurrentUser = currentUser.Id;

            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Home"));
            }

            return(View());
        }
        public async Task <IActionResult> Followers()
        {
            ViewBag.ActivePage = "Followers";

            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            ViewBag.CurrentUser = currentUser.Id;

            IQueryable <ConnectedUser> myFollowers         = _context.ConnectedUsers.Where(cu => cu.FollowingId == currentUser.Id);
            List <CustomUser>          filteredCustomUsers = new List <CustomUser>();

            foreach (CustomUser customUser in _userManager.Users)
            {
                if (myFollowers.Count() > 0 && customUser.Id != currentUser.Id)
                {
                    foreach (ConnectedUser myFollower in myFollowers)
                    {
                        if (customUser.Id == myFollower.FollowedById)
                        {
                            filteredCustomUsers.Add(customUser);
                        }
                    }
                }
            }

            FollowVM followVM = new FollowVM
            {
                FilteredCustomUsers = filteredCustomUsers,
                PairedUsers         = new List <string>()
            };

            foreach (ConnectedUser connectedUser in _context.ConnectedUsers)
            {
                foreach (ConnectedUser myFollower in myFollowers)
                {
                    if (connectedUser.FollowingId == myFollower.FollowedById && connectedUser.FollowedById == currentUser.Id)
                    {
                        followVM.PairedUsers.Add(myFollower.FollowedById);
                        break;
                    }
                    //else
                    //{
                    //    break;
                    //}
                }
            }

            return(View(followVM));
        }
        public async Task <IActionResult> UnFollowUser(string userId)
        {
            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            if (userId == null)
            {
                return(NotFound());
            }

            ConnectedUser connectedUserToBeUnFollowed = _context.ConnectedUsers.FirstOrDefault(cu => cu.FollowingId == userId && cu.FollowedById == currentUser.Id);

            _context.Remove(connectedUserToBeUnFollowed);
            await _context.SaveChangesAsync();

            return(Json(new { success = 200 }));
        }
        public async Task <IActionResult> Following()
        {
            ViewBag.ActivePage = "Following";

            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            ViewBag.CurrentUser = currentUser.Id;

            IQueryable <ConnectedUser> myFollowingUsers = _context.ConnectedUsers.Where(cu => cu.FollowedById == currentUser.Id);

            FollowVM followVM = new FollowVM
            {
                MyFollowingUsers = myFollowingUsers
            };

            return(View(followVM));
        }
        private bool AnySimilarBaseID(FormID targetFormID)
        {
            bool result = false;

            var allBaseObjects = objectDatabase.GetAllBaseObjectsFromDatabase();

            foreach (var baseObject in allBaseObjects)
            {
                if (baseObject.ID == targetFormID.BaseID &&
                    MainUtility.Check_ObjectType(baseObject) == targetFormID.ObjectType)
                {
                    result = true;
                }
            }

            return(result);
        }
        private bool PickableItemDataFormMatch(PickableScript pickScript)
        {
            bool result = false;

            var formID = target.Get_ObjectRefData().formID;

            ItemData itemDat = pickScript.Get_Pickable_Data().itemData;

            if (formID.BaseID == itemDat.ID &&
                formID.DatabaseID == itemDat.DatabaseName &&
                formID.ObjectType == MainUtility.Convert_ItemToObjectType(itemDat.item_Type))
            {
                result = true;
            }
            //match form with itemdat

            return(result);
        }
        public async Task <IActionResult> CreatePost(MyPostsVM myPostsVM)
        {
            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("MyPosts", "Profile", new { userId = currentUser.Id }));
            }

            Post post = new Post
            {
                PostContent   = myPostsVM.Post.PostContent.Trim(),
                CreatedAtTime = DateTime.Now,
                CustomUserId  = currentUser.Id
            };

            _context.Posts.Add(post);
            await _context.SaveChangesAsync();

            return(RedirectToAction("MyPosts", "Profile", new { userId = currentUser.Id }));
        }
        public async Task <IActionResult> FollowUser(string userId)
        {
            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            if (userId == null)
            {
                return(NotFound());
            }

            ConnectedUser connectedUser = new ConnectedUser
            {
                FollowingId  = userId,
                FollowedById = currentUser.Id
            };

            _context.ConnectedUsers.Add(connectedUser);
            await _context.SaveChangesAsync();

            await _context.SaveChangesAsync();

            return(Json(new { success = 200 }));
        }
        public async Task <IActionResult> ChangePassword(ChangePasswordVM changePasswordVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(changePasswordVM));
            }

            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            CustomUser customUserFromDb = await _userManager.FindByIdAsync(currentUser.Id);

            IdentityResult result = await _userManager.ChangePasswordAsync(customUserFromDb, changePasswordVM.CurrentPassword, changePasswordVM.NewPassword);

            await _userManager.UpdateAsync(customUserFromDb);

            if (!result.Succeeded)
            {
                ModelState.AddModelError("", "Hazırki şifrə yanlışdır və ya yeni şifrə tələblərə uyğun deyil.");
                return(View(changePasswordVM));
            }

            TempData["PasswordChanged"] = true;
            return(RedirectToAction("MyPosts", "Profile", new { userId = currentUser.Id }));
        }
        private void CreateNew_Pickables()
        {
            WorldObjectScript worldObjectScript = target as WorldObjectScript;
            PickableScript    pickableScript    = target as PickableScript;
            ActorScript       actorScript       = target as ActorScript;

            var dir  = NewFolder(target.gameObject.name);
            var path = $"{dir}/{target.gameObject.name}.prefab";

            var prefab1 = PrefabUtility.SaveAsPrefabAssetAndConnect(target.gameObject, path, InteractionMode.UserAction);

            ItemData_Type itemType = MainUtility.Convert_ObjectToItemType(pickableScript.Get_Pickable_Data().formID.ObjectType);

            if (itemType == ItemData_Type.Ammo)
            {
                Item_Ammo item = new Item_Ammo();
                item.ID        = pickableScript.Get_ObjectRefData().formID.BaseID;
                item.gameModel = prefab1;

                objectDatabase.Data.allItemAmmo.Add(item);
            }
            else if (itemType == ItemData_Type.Armor)
            {
                Item_Armor item = new Item_Armor();
                item.ID        = pickableScript.Get_ObjectRefData().formID.BaseID;
                item.gameModel = prefab1;

                objectDatabase.Data.allItemArmors.Add(item);
            }
            else if (itemType == ItemData_Type.Consume)
            {
                Item_Consumables item = new Item_Consumables();
                item.ID        = pickableScript.Get_ObjectRefData().formID.BaseID;
                item.gameModel = prefab1;

                objectDatabase.Data.allItemConsumables.Add(item);
            }
            else if (itemType == ItemData_Type.Junk)
            {
                Item_Junk item = new Item_Junk();
                item.ID        = pickableScript.Get_ObjectRefData().formID.BaseID;
                item.gameModel = prefab1;

                objectDatabase.Data.allItemJunk.Add(item);
            }
            else if (itemType == ItemData_Type.Key)
            {
                Item_Key item = new Item_Key();
                item.ID        = pickableScript.Get_ObjectRefData().formID.BaseID;
                item.gameModel = prefab1;

                objectDatabase.Data.allItemKey.Add(item);
            }
            else if (itemType == ItemData_Type.Misc)
            {
                Item_Misc item = new Item_Misc();
                item.ID        = pickableScript.Get_ObjectRefData().formID.BaseID;
                item.gameModel = prefab1;

                objectDatabase.Data.allItemMiscs.Add(item);
            }
            else if (itemType == ItemData_Type.Weapon)
            {
                Item_Weapon item = new Item_Weapon();
                item.ID        = pickableScript.Get_ObjectRefData().formID.BaseID;
                item.gameModel = prefab1;

                objectDatabase.Data.allItemWeapon.Add(item);
            }
        }
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            chestContainer = (ChestContainer)target;

            var stagePrefab  = chestContainer.gameObject.scene;
            var EditorScenes = EditorSceneManager.GetActiveScene();

            if (stagePrefab == null)
            {
                return;
            }


            if (EditorScenes.name != stagePrefab.name)
            {
                return;
            }



            EditorUtility.SetDirty(target);


            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Container Editor", EditorStyles.boldLabel);
            currentDatabase = (ObjectDatabase)EditorGUILayout.ObjectField(currentDatabase, typeof(ObjectDatabase), false, GUILayout.MaxWidth(200));

            tempContainer = chestContainer.itemContainer;

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginVertical("Box");
            {
                List <string> options = new List <string>();
                List <Item>   items   = new List <Item>();

                if (currentDatabase != null)
                {
                    itemType = (ItemData_Type)EditorGUILayout.EnumPopup("Item type", itemType);

                    if (itemType == ItemData_Type.Ammo)
                    {
                        items.AddRange(currentDatabase.Data.allItemAmmo);
                    }
                    else if (itemType == ItemData_Type.Junk)
                    {
                        items.AddRange(currentDatabase.Data.allItemJunk);
                    }
                    else if (itemType == ItemData_Type.Key)
                    {
                        items.AddRange(currentDatabase.Data.allItemKey);
                    }
                    else if (itemType == ItemData_Type.Weapon)
                    {
                        items.AddRange(currentDatabase.Data.allItemWeapon);
                    }
                    else if (itemType == ItemData_Type.Misc)
                    {
                        items.AddRange(currentDatabase.Data.allItemMiscs);
                    }

                    items.OrderBy(z => z);

                    foreach (Item item in items)
                    {
                        options.Add(item.ID);
                    }
                }
                selectedItem = EditorGUILayout.Popup("Item", selectedItem, options.ToArray());

                if (items.Count > selectedItem)
                {
                    if (items[selectedItem] != null)
                    {
                        currentItem = items[selectedItem];
                    }
                }
                if (GUILayout.Button("Add Item", GUILayout.Width(100)))
                {
                    if (currentItem != null)
                    {
                        ItemData newItem = new ItemData();
                        newItem.ID           = currentItem.ID;
                        newItem.DatabaseName = currentDatabase.Data.name;
                        newItem.count        = 1;
                        newItem.item_Type    = MainUtility.Check_ItemType(currentItem);

                        tempContainer.all_InventoryItem.Add(newItem);
                    }
                    else
                    {
                        Debug.LogError("No item!");
                    }
                }
            }
            EditorGUILayout.EndVertical();


            EditorGUILayout.BeginVertical("Box");
            {
                foreach (ItemData itemDat in tempContainer.all_InventoryItem)
                {
                    EditorGUILayout.BeginHorizontal("Box");
                    {
                        GenericMenu menu = new GenericMenu();
                        itemDat.count = EditorGUILayout.IntField(itemDat.count, GUILayout.Width(40));

                        if (GUILayout.Button(itemDat.DatabaseName + " | " + itemDat.ID, buttonStyle))
                        {
                            menu.AddItem(new GUIContent("Empty"), false, EmptyFunc);
                            menu.AddItem(new GUIContent("Duplicate"), false, Context_Duplicate, itemDat);
                            menu.AddItem(new GUIContent("Delete"), false, Context_Delete, itemDat);
                            menu.ShowAsContext();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Chest Container");
                chestContainer.itemContainer = tempContainer;
            }
        }
Example #17
0
        public HistoryViewModel()
        {
            try
            {
                var lst_log = new MainUtility().LoadHistory();
                if (lst_log == null)
                {
                    Logs = new ObservableCollection <LogContent>();
                    return;
                }
                _logs = lst_log;
                List <LogContent> logss      = new List <LogContent>();
                float             time_day30 = (Int32)(DateTime.UtcNow.AddDays(-30).Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                var item_day30 = _logs.history.history_bytesave.Where(x => x.time_log < time_day30);
                _logs.history.history_bytesave.Remove(item_day30);
                new MainUtility().WriteHistory(_logs.history);
                foreach (var item in _logs.history.history_bytesave)
                {
                    logss.Add(new LogContent
                    {
                        Content       = item.log_content,
                        TimeDisplay   = new DateTime(1970, 1, 1).AddSeconds(item.time_log).ToLocalTime().ToString("dd/MM/yyyy hh:MM:ss tt"),
                        Time          = item.time_log.ToString(),
                        Tittle        = item.function,
                        StatusSuccess = item.status == 1 ? "Visible" : "Hidden",
                        StatusFalse   = item.status == 1 ? "Hidden" : "Visible"
                    });
                }


                //foreach (var item in _log)
                //{
                //    var a = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(float.Parse(item.time_log)).ToLocalTime().ToString("dd/MM/yyyy hh:MM:ss tt");

                //    List<LogContent> lst = new List<LogContent>();
                //    lst.Add(new LogContent() { Content = item.function });
                //    Logs _logss = new Logs();
                //    _logss.LogContents.Add(lst);
                //    //_logs.LogContents.Add(new LogContent()
                //    //{
                //    //    Content = item.log_content,
                //    //    TimeDisplay = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(float.Parse(item.time_log)).ToLocalTime().ToString("dd/MM/yyyy hh:MM:ss tt"),
                //    //    Time = item.time_log,
                //    //    Tittle = item.function.ToString(),
                //    //    StatusFalse = "Visible",
                //    //    StatusSuccess = "Hidden",
                //    //    //});
                //    //    //_logs.LogContents.Add(
                //    //    //new LogContent
                //    //    //{
                //    //    //    Tittle = "",
                //    //    //    //Time = DateTime.Now,
                //    //    //    TimeDisplay = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"),
                //    //    //    Content = "",
                //    //    //    StatusSuccess = 1 == 1 ? "Visible" : "Hidden",
                //    //    //    StatusFalse = 0 == 1 ? "Hidden" : "Visible"
                //    //    //}
                //    //});
                //}
                //_log.LogContents.RemoveAll(x => x.Time < (DateTime.Now.AddDays(-30)));
                //new MainUtility().WriteLog(_log);
                Logs = new ObservableCollection <LogContent>(logss.OrderByDescending(x => x.Time));
            }
            catch (Exception)
            {
                Logs = new ObservableCollection <LogContent>(new List <LogContent>());
            }
        }
Example #18
0
        private void YearSelectorDropdown_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var dt = MainUtility.GetDataTableFromCsv(YearSelectorDropdown.SelectedItem.ToString());

            CSVDataGridView.ItemsSource = dt.DefaultView;
        }