Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions GST_Program.Domain/Models/BadgeHistory.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;

namespace GST_Program.Domain.Models {
public class BadgeHistory {
public int Transaction_Num { get; set; }
public string Badge_ID { get; set; }
public string Giver_ID { get; set; }
public string Student_ID { get; set; }
public DateTime Time_Stamp { get; set; }
public string Comment { get; set; }
public int Pos_X { get; set; }
public int Pos_Y { get; set; }

public Badge Badge { get; set; }
public Person Giver { get; set; }
public Person Receiver { get; set; }
}
using System;

namespace GST_Program.Domain.Models {
public class BadgeHistory {
public int Transaction_Num { get; set; }
public string Badge_ID { get; set; }
public string Giver_ID { get; set; }
public string Student_ID { get; set; }
public DateTime Time_Stamp { get; set; }
public string Comment { get; set; }
public int Pos_X { get; set; }
public int Pos_Y { get; set; }
public int Angle { get; set; }

public Badge Badge { get; set; }
public Person Giver { get; set; }
public Person Receiver { get; set; }
}
}
2 changes: 1 addition & 1 deletion GST_Program.Domain/Services/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Create(Badge b) {
// Create new row in BadgeHistory
public void Create(BadgeHistory b) {
using (IDbConnection db = new SqlConnection(connection)) {
string sqlQuery = "INSERT INTO BadgeHistory VALUES(@Badge_ID, @Giver_ID, @Student_ID, @Time_Stamp, @Comment)";
string sqlQuery = "INSERT INTO BadgeHistory VALUES(@Badge_ID, @Giver_ID, @Student_ID, @Time_Stamp, @Comment, @Pos_X, @Pos_Y, @Angle)";
db.Execute(sqlQuery, b);
}
}
Expand Down
3 changes: 2 additions & 1 deletion GST_Program.Domain/Sql/CreateTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ CREATE TABLE [BadgeHistory](
[Time_Stamp] DateTime,
[Comment] varchar(50),
[Pos_X] int,
[Pos_Y] int
[Pos_Y] int,
[Angle] int
);

CREATE TABLE [CoreRelation](
Expand Down
6 changes: 3 additions & 3 deletions GST_Program.Domain/Sql/InsertDummyData.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ INSERT INTO [BadgeBank] VALUES


INSERT INTO [BadgeHistory] VALUES
('201','10010','10010','11/4/16','I read',100,100)
,('206','10014','10010','11/7/16','BEYOND!',100,200)
,('514','10011','10010','11/12/16','Competency test',100,300);
('201','10010','10010','11/4/16','I read',100,100,0)
,('206','10014','10010','11/7/16','BEYOND!',100,200,90)
,('514','10011','10010','11/12/16','Competency test',100,300,270);


INSERT INTO [CoreRelation] VALUES
Expand Down
Binary file modified GST_Program.Domain/bin/Debug/GST_Program.Domain.dll
Binary file not shown.
Binary file modified GST_Program.Domain/bin/Debug/GST_Program.Domain.pdb
Binary file not shown.
3 changes: 2 additions & 1 deletion GST_Program.Domain/bin/Debug/Sql/CreateTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ CREATE TABLE [BadgeHistory](
[Time_Stamp] DateTime,
[Comment] varchar(50),
[Pos_X] int,
[Pos_Y] int
[Pos_Y] int,
[Angle] int
);

CREATE TABLE [CoreRelation](
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified GST_Program.Domain/obj/Debug/GST_Program.Domain.dll
Binary file not shown.
Binary file modified GST_Program.Domain/obj/Debug/GST_Program.Domain.pdb
Binary file not shown.
206 changes: 108 additions & 98 deletions GST_Program/Controllers/TreeController.cs
Original file line number Diff line number Diff line change
@@ -1,99 +1,109 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using GST_Program.Domain.Models;
using GST_Program.Domain.Services;
using GST_Program.Models;

namespace GST_Program.Controllers {
public class TreeController : Controller {

// GET: Tree
public ActionResult Index(string id) {
var service = new Database();
List<BadgeHistory> b = service.ReadAllBadgeReceivedByReceiver(id);
return View(b);
}


// GET: Tree/Grid
public ActionResult Grid(string id) {
var service = new Database();
var person = service.ReadSinglePerson(id);
ViewBag.Person = person;

List<Core> core = service.ReadAllCores();
ViewBag.Core = core;

var badgeHistoryList = service.ReadAllBadgeReceivedByReceiver(id);

return View(badgeHistoryList);
}


// GET: Tree/BadgeHistoryDetail
public ActionResult BadgeHistoryDetail(string id) {
var service = new Database();
var b = service.ReadSingleBadgeReceived(id);
return View(b);
}

#region Give Badge

// GET: Tree/GiveBadge
public ActionResult GiveBadge() {
var service = new Database();
var bb = service.ReadAllBadge();

var pvm = service.ReadAllPerson();

ViewBag.Badges = bb;
ViewBag.People = pvm;

return View();
}


// POST: Tree/GiveBadge
[HttpPost]
public ActionResult GiveBadge(FormCollection form) {
var service = new Database();
BadgeHistory b = new BadgeHistory();

var badge = form["badge"];
var giver = form["giver"];
var receiver = form["receiver"];
var comment = form["Comment"];

// Test to see if Form Input for Badge is a Name or a Number
if (!TestString.IsAllDigits(badge)) {
b.Badge = service.ReadSingleBadgeByName(badge);
b.Badge_ID = Convert.ToString(b.Badge.Badge_ID);
}

// Test to see if Form Input for Giver is a Name or a Number
if (!TestString.IsAllDigits(giver)) {
b.Giver = service.ReadSinglePersonByName(giver);
b.Giver_ID = Convert.ToString(b.Giver.Person_ID);
}

// Test to see if Form Input for Receiver is a Name or a Number
if (!TestString.IsAllDigits(receiver)) {
b.Receiver = service.ReadSinglePersonByName(receiver);
b.Student_ID = Convert.ToString(b.Receiver.Person_ID);
}

b.Time_Stamp = DateTime.Now;
b.Comment = comment;

if (ModelState.IsValid) {
service.Create(b);
return RedirectToAction($"Grid/{b.Student_ID}");
}

return View(b);
}

#endregion
}
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using GST_Program.Domain.Models;
using GST_Program.Domain.Services;
using GST_Program.Models;

namespace GST_Program.Controllers {
public class TreeController : Controller {

// GET: Tree
public ActionResult Index(string id) {
var service = new Database();
List<BadgeHistory> b = service.ReadAllBadgeReceivedByReceiver(id);
return View(b);
}


// GET: Tree/Grid
public ActionResult Grid(string id) {
var service = new Database();
var person = service.ReadSinglePerson(id);
ViewBag.Person = person;

List<Core> core = service.ReadAllCores();
ViewBag.Core = core;

var badgeHistoryList = service.ReadAllBadgeReceivedByReceiver(id);

return View(badgeHistoryList);
}


// GET: Tree/BadgeHistoryDetail
public ActionResult BadgeHistoryDetail(string id) {
var service = new Database();
var b = service.ReadSingleBadgeReceived(id);
return View(b);
}

#region Give Badge

// GET: Tree/GiveBadge
public ActionResult GiveBadge() {
var service = new Database();
var bb = service.ReadAllBadge();

var pvm = service.ReadAllPerson();

ViewBag.Badges = bb;
ViewBag.People = pvm;

return View();
}


// POST: Tree/GiveBadge
[HttpPost]
public ActionResult GiveBadge(FormCollection form) {
var service = new Database();
BadgeHistory b = new BadgeHistory();

var badge = form["badge"];
var giver = form["giver"];
var receiver = form["receiver"];
var comment = form["Comment"];

// Test to see if Form Input for Badge is a Name or a Number
if (!TestString.IsAllDigits(badge)) {
b.Badge = service.ReadSingleBadgeByName(badge);
b.Badge_ID = Convert.ToString(b.Badge.Badge_ID);
}

// Test to see if Form Input for Giver is a Name or a Number
if (!TestString.IsAllDigits(giver)) {
b.Giver = service.ReadSinglePersonByName(giver);
b.Giver_ID = Convert.ToString(b.Giver.Person_ID);
}

// Test to see if Form Input for Receiver is a Name or a Number
if (!TestString.IsAllDigits(receiver)) {
b.Receiver = service.ReadSinglePersonByName(receiver);
b.Student_ID = Convert.ToString(b.Receiver.Person_ID);
}

b.Time_Stamp = DateTime.Now;
b.Comment = comment;

var count = service.ReadAllBadgeReceivedByReceiver(b.Student_ID).Count;

//replace '1' with the badge count for a person (or any positive number if you want a different position)
TreeAlgorithm.point bPos = TreeAlgorithm.TreePos(TreeAlgorithm.BinPercent(count),-32.0f);

b.Pos_X = bPos.pos_x;
b.Pos_Y = bPos.pos_y;
b.Angle = bPos.angle;
//rotation angle will be put here

if (ModelState.IsValid) {
service.Create(b);
return RedirectToAction($"Grid/{b.Student_ID}");
}

return View(b);
}

#endregion
}
}
Loading