示例#1
0
        public async Task <IActionResult> OnPost(int expertId)
        {
            Expert = expertData.GetById(expertId);
            if (Expert == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            userProfile          = accountData.GetById(Expert.userId);
            userProfile.IsExpert = false;
            accountData.Update(userProfile);

            foreach (var answer in Expert.Answers)
            {
                answerData.Delete(answer);
            }

            await answerData.Commit();

            expertData.Delete(Expert);

            if (await expertData.Commit())
            {
                if (await accountData.Commit())
                {
                    TempData["Message"] = $"Expert {Expert.firstName} {Expert.lastName} Deleted";
                    return(RedirectToPage("./ManageExperts"));
                }
            }
            return(RedirectToPage("./NotFound"));
        }
        public async Task <IActionResult> OnPost(string userId)
        {
            userProfile = accountData.GetById(userId);

            userProfile.IsAdmin = true;
            accountData.Update(userProfile);

            if (await accountData.Commit())
            {
                TempData["Message"] = $"{userProfile.UserName} has been promoted to Admin";
                return(RedirectToPage("./ListUsers"));
            }
            return(RedirectToPage("./NotFound"));
        }
示例#3
0
        public async Task <IActionResult> OnPost(string userId)
        {
            userProfile = accountData.GetById(userId);

            userProfile.IsBanned = false;
            accountData.Update(userProfile);

            if (await accountData.Commit())
            {
                TempData["Message"] = $"{userProfile.UserName} has been restored to good standing";
                return(RedirectToPage("./ListUsers"));
            }
            return(RedirectToPage("./NotFound"));
        }
示例#4
0
        public async Task <IActionResult> OnPost(string userId)
        {
            userProfile          = accountData.GetById(userId);
            userProfile.IsExpert = false;

            expert = expertData.GetByUserId(userId);
            expertData.Delete(expert);

            if (await expertData.Commit() && await accountData.Commit())
            {
                TempData["Message"] = $"Expert {expert.firstName} {expert.lastName} deleted";
                return(RedirectToPage("./ListUsers"));
            }
            return(RedirectToPage("./NotFound"));
        }
示例#5
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            accountData.Update(userProfile);
            if (await accountData.Commit())
            {
                TempData["Message"] = $"User {userProfile.firstName} {userProfile.lastName} updated";
                return(RedirectToPage("./ListUsers"));
            }
            return(RedirectToPage("./NotFound"));
        }
示例#6
0
        public async Task<IActionResult> OnPost(string userId)
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

            MemoryStream ms = new MemoryStream();

            foreach (var file in Request.Form.Files)
            {
                file.CopyTo(ms);
            }

            expert = new Expert
            {
                firstName = Input.firstName,
                lastName = Input.lastName,
                bio = Input.bio,
                specialty = Input.specialty,
                userId = Input.userId,
                image = ms.ToArray()
            };

            ms.Close();
            ms.Dispose();

            userProfile = accountData.GetById(userId);
            userProfile.IsExpert = true;
            
            accountData.Update(userProfile);
            expertData.Add(expert);

            if (await expertData.Commit() && await accountData.Commit())
            {
                TempData["Message"] = $"{userProfile.firstName} {userProfile.lastName} added as expert";
                return RedirectToPage("./ListUsers");
            }
            return RedirectToPage("./NotFound");            
        }