mirror of
https://github.com/guilhermewerner/site-pi
synced 2025-06-16 05:44:20 +00:00
Initial commit
This commit is contained in:
63
SitePi/Controllers/HomeController.cs
Normal file
63
SitePi/Controllers/HomeController.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SitePi.Models;
|
||||
|
||||
namespace SitePi.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private AppContext AppContext;
|
||||
|
||||
public HomeController(AppContext AppContext)
|
||||
{
|
||||
this.AppContext = AppContext;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
ViewBag.Bots = AppContext.Bots;
|
||||
ViewBag.Users = AppContext.Users;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public FileResult BaixarBot(int id)
|
||||
{
|
||||
Bot bot = AppContext.Bots.Find(id);
|
||||
|
||||
byte[] FileBytes = System.IO.File.ReadAllBytes(bot.FileBytes);
|
||||
string FileName = bot.FileName;
|
||||
return File(FileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, FileName);
|
||||
}
|
||||
|
||||
public IActionResult DeleteBot(int id)
|
||||
{
|
||||
Bot bot = AppContext.Bots.Find(id);
|
||||
|
||||
if (bot != null)
|
||||
{
|
||||
AppContext.Bots.Remove(bot);
|
||||
AppContext.SaveChanges();
|
||||
}
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
155
SitePi/Controllers/QuizController.cs
Normal file
155
SitePi/Controllers/QuizController.cs
Normal file
@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SitePi.Models;
|
||||
|
||||
namespace SitePi.Controllers
|
||||
{
|
||||
public class QuizController : Controller
|
||||
{
|
||||
private AppContext AppContext;
|
||||
|
||||
private int AmountA = 0;
|
||||
private int AmountB = 0;
|
||||
private int AmountC = 0;
|
||||
private int AmountD = 0;
|
||||
|
||||
private int QuestionsCount = 0;
|
||||
|
||||
public QuizController(AppContext AppContext)
|
||||
{
|
||||
this.AppContext = AppContext;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
Quiz Current = AppContext.Quizzes.Find(1);
|
||||
|
||||
ViewBag.Users = AppContext.Users;
|
||||
|
||||
ViewData["QuizTitle"] = Current.Name;
|
||||
|
||||
ViewBag.Questions = AppContext.Questions.Where(q => q.QuizId == 1);
|
||||
|
||||
ViewBag.Choices = AppContext.Choices;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Index(Responds rep)
|
||||
{
|
||||
User Logged = AppContext.Users.Find(rep.UserId);
|
||||
int UserId = rep.UserId;
|
||||
|
||||
Quiz Current = AppContext.Quizzes.Find(1);
|
||||
int QuizId = AppContext.Quizzes.Find(1).Id;
|
||||
|
||||
ViewBag.Questions = AppContext.Questions.Where(q => q.QuizId == 1);
|
||||
|
||||
foreach (Question q in ViewBag.Questions)
|
||||
{
|
||||
QuestionsCount++;
|
||||
}
|
||||
|
||||
rep.UserId = UserId;
|
||||
rep.User = Logged;
|
||||
|
||||
rep.QuizId = QuizId;
|
||||
rep.Quiz = Current;
|
||||
|
||||
Check(rep.Profile_1);
|
||||
Check(rep.Profile_2);
|
||||
Check(rep.Profile_3);
|
||||
Check(rep.Profile_4);
|
||||
Check(rep.Profile_5);
|
||||
Check(rep.Profile_6);
|
||||
Check(rep.Profile_7);
|
||||
|
||||
int PercentageA = (AmountA * 100) / 7; //Criatividade
|
||||
int PercentageB = (AmountB * 100) / 7; //Liderança
|
||||
int PercentageC = (AmountC * 100) / 7; //Individualista
|
||||
int PercentageD = (AmountD * 100) / 7; //Insegurança
|
||||
|
||||
string _Name = "";
|
||||
string _FileBytes = "";
|
||||
string _FileName = "";
|
||||
|
||||
if (PercentageA >= 50)
|
||||
{
|
||||
_Name = "Responsive";
|
||||
_FileBytes = @".\wwwroot\uploads\HunterBot.java";
|
||||
_FileName = "ResponsiveBot.java";
|
||||
}
|
||||
else if (PercentageB >= 50)
|
||||
{
|
||||
_Name = "Communicating";
|
||||
_FileBytes = @".\wwwroot\uploads\HunterBot.java";
|
||||
_FileName = "CommunicatingBot.java";
|
||||
}
|
||||
else if (PercentageC >= 50)
|
||||
{
|
||||
_Name = "Hunter";
|
||||
_FileBytes = @".\wwwroot\uploads\HunterBot.java";
|
||||
_FileName = "HunterBot.java";
|
||||
}
|
||||
else
|
||||
{
|
||||
_Name = "Hide";
|
||||
_FileBytes = @".\wwwroot\uploads\HunterBot.java";
|
||||
_FileName = "HideBot.java";
|
||||
}
|
||||
|
||||
Bot bot = new Bot
|
||||
{
|
||||
Name = _Name,
|
||||
|
||||
FileBytes = _FileBytes,
|
||||
FileName = _FileName,
|
||||
|
||||
User = Logged,
|
||||
UserId = Logged.Id,
|
||||
|
||||
PercentageA = PercentageA,
|
||||
PercentageB = PercentageB,
|
||||
PercentageC = PercentageC,
|
||||
PercentageD = PercentageD
|
||||
};
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
AppContext.Bots.Add(bot);
|
||||
AppContext.SaveChanges();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
return View("Index", Response);
|
||||
}
|
||||
|
||||
public void Check(string choice)
|
||||
{
|
||||
switch (choice)
|
||||
{
|
||||
case "a":
|
||||
AmountA++;
|
||||
break;
|
||||
case "b":
|
||||
AmountB++;
|
||||
break;
|
||||
case "c":
|
||||
AmountC++;
|
||||
break;
|
||||
case "d":
|
||||
AmountD++;
|
||||
break;
|
||||
default:
|
||||
AmountD++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
SitePi/Controllers/UserController.cs
Normal file
113
SitePi/Controllers/UserController.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SitePi.Models;
|
||||
|
||||
namespace SitePi.Controllers
|
||||
{
|
||||
public class UserController : Controller
|
||||
{
|
||||
private AppContext AppContext;
|
||||
|
||||
public UserController(AppContext AppContext)
|
||||
{
|
||||
this.AppContext = AppContext;
|
||||
}
|
||||
|
||||
[HttpGet("User/{id}")]
|
||||
public IActionResult Index(int Id)
|
||||
{
|
||||
User user = AppContext.Users.Find(Id);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
ViewBag.User = user;
|
||||
|
||||
ViewBag.Bots = AppContext.Bots.Where(b => b.UserId == user.Id);
|
||||
|
||||
float TotalA = 0;
|
||||
float TotalB = 0;
|
||||
float TotalC = 0;
|
||||
float TotalD = 0;
|
||||
|
||||
foreach (Bot b in ViewBag.Bots)
|
||||
{
|
||||
TotalA = TotalA + (b.PercentageA * 7) / 100;
|
||||
TotalB = TotalB + (b.PercentageB * 7) / 100;
|
||||
TotalC = TotalC + (b.PercentageC * 7) / 100;
|
||||
TotalD = TotalD + (b.PercentageD * 7) / 100;
|
||||
}
|
||||
|
||||
ViewData["TotalA"] = TotalA;
|
||||
ViewData["TotalB"] = TotalB;
|
||||
ViewData["TotalC"] = TotalC;
|
||||
ViewData["TotalD"] = TotalD;
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
public IActionResult New()
|
||||
{
|
||||
return View("Form");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult New(User user)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
AppContext.Users.Add(user);
|
||||
AppContext.SaveChanges();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
return View("Form", user);
|
||||
}
|
||||
|
||||
public IActionResult Edit(int id)
|
||||
{
|
||||
User user = AppContext.Users.Find(id);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return View("Form", user);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Edit(User user)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
AppContext.Users.Update(user);
|
||||
AppContext.SaveChanges();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
return View("Form", user);
|
||||
}
|
||||
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
User user = AppContext.Users.Find(id);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
AppContext.Users.Remove(user);
|
||||
AppContext.SaveChanges();
|
||||
}
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user