user login, register, hashed passwords, announcements start
This commit is contained in:
@@ -1,74 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ClassDiagram MajorVersion="1" MinorVersion="1">
|
||||
<Class Name="StudentHouseDashboard.Models.Announcement" BaseTypeListCollapsed="true">
|
||||
<Position X="4.75" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAACAAAAAEgAEAAiAAAAAAAAAAAAAAAAAAAAAAAIhA=</HashCode>
|
||||
<FileName>Models\Announcement.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<Lollipop Position="0.2" Collapsed="true" />
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.Comment" BaseTypeListCollapsed="true">
|
||||
<Position X="6.5" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAFgAEAAiAAAAAAAAAAAAAAAAAAAAAAAABA=</HashCode>
|
||||
<FileName>Models\Comment.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<Lollipop Position="0.2" Collapsed="true" />
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.Complaint" BaseTypeListCollapsed="true">
|
||||
<Position X="8.25" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAEAAAgAEAAiAAAAAAAAAAAAAAAAAAAAAQAAAA=</HashCode>
|
||||
<FileName>Models\Complaint.cs</FileName>
|
||||
<HashCode>AAAACAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIhA=</HashCode>
|
||||
<FileName>Models\Announcement.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<Lollipop Position="0.2" Collapsed="true" />
|
||||
<Lollipop Position="0.2" />
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.Event" BaseTypeListCollapsed="true">
|
||||
<Class Name="StudentHouseDashboard.Models.Comment" BaseTypeListCollapsed="true">
|
||||
<Position X="10" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAEgAEAAiAAAAAAgAAAAAAAAAAAAAEAAABA=</HashCode>
|
||||
<HashCode>AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA=</HashCode>
|
||||
<FileName>Models\Comment.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<Lollipop Position="0.2" />
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.Complaint" BaseTypeListCollapsed="true">
|
||||
<Position X="4.75" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAA=</HashCode>
|
||||
<FileName>Models\Complaint.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.Event" BaseTypeListCollapsed="true">
|
||||
<Position X="6.5" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAEAAAAA=</HashCode>
|
||||
<FileName>Models\Event.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
<Lollipop Position="0.2" Collapsed="true" />
|
||||
</Class>
|
||||
<Class Name="StudentHouseDashboard.Models.User">
|
||||
<Position X="11.75" Y="2" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAAAAAAEQAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<HashCode>AAAAAAAAAAAAAAAAEAAAABQAAAAEAAACAAAAAgAAAAA=</HashCode>
|
||||
<FileName>Models\User.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Class>
|
||||
<Interface Name="StudentHouseDashboard.Models.IMessage">
|
||||
<Position X="11.75" Y="5.25" Width="1.5" />
|
||||
<Class Name="StudentHouseDashboard.GenericMessage">
|
||||
<Position X="8.25" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAAgAEAAiAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Models\IMessage.cs</FileName>
|
||||
<HashCode>AAAAAAAAQAAoAEAAqAAAAIAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Models\GenericMessage.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Interface>
|
||||
</Class>
|
||||
<Interface Name="StudentHouseDashboard.Models.IVotable">
|
||||
<Position X="10" Y="5.25" Width="1.5" />
|
||||
<Position X="10" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA=</HashCode>
|
||||
<FileName>Models\IVotable.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Interface>
|
||||
<Enum Name="StudentHouseDashboard.Models.ComplaintSeverity">
|
||||
<Position X="4.75" Y="5.25" Width="1.5" />
|
||||
<Position X="4.75" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAEgAAAACgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Models\ComplaintSeverity.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Enum Name="StudentHouseDashboard.Models.ComplaintStatus">
|
||||
<Position X="6.5" Y="5.25" Width="1.5" />
|
||||
<Position X="6.5" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAAAAAAABAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAA=</HashCode>
|
||||
<FileName>Models\ComplaintStatus.cs</FileName>
|
||||
</TypeIdentifier>
|
||||
</Enum>
|
||||
<Enum Name="StudentHouseDashboard.Models.UserRole">
|
||||
<Position X="8.25" Y="5.25" Width="1.5" />
|
||||
<Position X="11.75" Y="6.25" Width="1.5" />
|
||||
<TypeIdentifier>
|
||||
<HashCode>AAQAAAAAAAAAAAAAAAAAAAAAQAAAAQAAAAAAAAAAAAA=</HashCode>
|
||||
<FileName>Models\UserRole.cs</FileName>
|
||||
|
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StudentHouseDashboard.Managers
|
||||
{
|
||||
public class AnnouncementManager
|
||||
{
|
||||
}
|
||||
}
|
41
StudentHouseDashboard/HouseData/Managers/UserManager.cs
Normal file
41
StudentHouseDashboard/HouseData/Managers/UserManager.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using StudentHouseDashboard.Models;
|
||||
using StudentHouseDashboard.Repositories;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StudentHouseDashboard.Managers
|
||||
{
|
||||
public class UserManager
|
||||
{
|
||||
private UserRepository userRepository;
|
||||
public UserManager()
|
||||
{
|
||||
userRepository = new UserRepository();
|
||||
}
|
||||
public List<User> GetAllUsers()
|
||||
{
|
||||
return userRepository.GetAllUsers();
|
||||
}
|
||||
public User GetUserById(int id)
|
||||
{
|
||||
return userRepository.GetUserById(id);
|
||||
}
|
||||
public bool CreateUser(string name, string password, UserRole role)
|
||||
{
|
||||
return userRepository.CreateUser(name, password, role);
|
||||
}
|
||||
public void UpdateUser(int id, string name, string password, UserRole role)
|
||||
{
|
||||
userRepository.UpdateUser(id, name, password, role);
|
||||
}
|
||||
public void DisableUser(int id)
|
||||
{
|
||||
userRepository.DisableUser(id);
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,37 +5,29 @@ using System.Text;
|
||||
|
||||
namespace StudentHouseDashboard.Models
|
||||
{
|
||||
public class Announcement : IMessage, IVotable
|
||||
public class Announcement : GenericMessage, IVotable
|
||||
{
|
||||
public Announcement(User author, string description, string title, DateTime publishDate, bool isImportant, bool isSticky) : base(author, description, title, publishDate)
|
||||
{
|
||||
IsImportant = isImportant;
|
||||
IsSticky = isSticky;
|
||||
}
|
||||
|
||||
public List<Comment> Comments
|
||||
{
|
||||
get => default;
|
||||
set
|
||||
{
|
||||
}
|
||||
get;set;
|
||||
}
|
||||
|
||||
public int IsImportant
|
||||
public bool IsImportant
|
||||
{
|
||||
get => default;
|
||||
set
|
||||
{
|
||||
}
|
||||
get;set;
|
||||
}
|
||||
|
||||
public int IsSticky
|
||||
public bool IsSticky
|
||||
{
|
||||
get => default;
|
||||
set
|
||||
{
|
||||
}
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string Description { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public User Author { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public DateTime PublishDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public void DownVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
@@ -5,19 +5,11 @@ using System.Text;
|
||||
|
||||
namespace StudentHouseDashboard.Models
|
||||
{
|
||||
public class Comment : IMessage, IVotable
|
||||
public class Comment : GenericMessage, IVotable
|
||||
{
|
||||
public int Responses
|
||||
public Comment(User author, string description, string title, DateTime publishDate) : base(author, description, title, publishDate)
|
||||
{
|
||||
get => default;
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string Description { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public User Author { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public DateTime PublishDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public void DownVote()
|
||||
{
|
||||
|
@@ -5,27 +5,27 @@ using System.Text;
|
||||
|
||||
namespace StudentHouseDashboard.Models
|
||||
{
|
||||
public class Complaint : IMessage
|
||||
public class Complaint : GenericMessage
|
||||
{
|
||||
public Complaint(User author, string description, string title, DateTime publishDate, ComplaintStatus status, ComplaintSeverity severity) : base(author, description, title, publishDate)
|
||||
{
|
||||
Status = status;
|
||||
Severity = severity;
|
||||
}
|
||||
|
||||
public ComplaintStatus Status
|
||||
{
|
||||
get => default;
|
||||
set
|
||||
{
|
||||
}
|
||||
get;set;
|
||||
}
|
||||
|
||||
public ComplaintSeverity Severity
|
||||
{
|
||||
get => default;
|
||||
set
|
||||
{
|
||||
}
|
||||
get;set;
|
||||
}
|
||||
|
||||
public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string Description { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public User Author { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public DateTime PublishDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public List<Comment> Responses
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,37 +5,22 @@ using System.Text;
|
||||
|
||||
namespace StudentHouseDashboard.Models
|
||||
{
|
||||
public class Event : IMessage, IVotable
|
||||
public class Event : GenericMessage
|
||||
{
|
||||
public int StartDate
|
||||
public Event(User author, string description, string title, DateTime publishDate, DateTime startDate, DateTime endDate) : base(author, description, title, publishDate)
|
||||
{
|
||||
get => default;
|
||||
set
|
||||
{
|
||||
}
|
||||
StartDate = startDate;
|
||||
EndDate = endDate;
|
||||
}
|
||||
|
||||
public int EndDate
|
||||
public DateTime StartDate
|
||||
{
|
||||
get => default;
|
||||
set
|
||||
{
|
||||
}
|
||||
get;set;
|
||||
}
|
||||
|
||||
public string Title { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string Description { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public User Author { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public DateTime PublishDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public void DownVote()
|
||||
public DateTime EndDate
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UpVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
get;set;
|
||||
}
|
||||
}
|
||||
}
|
45
StudentHouseDashboard/HouseData/Models/GenericMessage.cs
Normal file
45
StudentHouseDashboard/HouseData/Models/GenericMessage.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using StudentHouseDashboard.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StudentHouseDashboard
|
||||
{
|
||||
public abstract class GenericMessage
|
||||
{
|
||||
private User author;
|
||||
private string description;
|
||||
private string title;
|
||||
private DateTime publishDate;
|
||||
|
||||
protected GenericMessage(User author, string description, string title, DateTime publishDate)
|
||||
{
|
||||
Author = author;
|
||||
Description = description;
|
||||
Title = title;
|
||||
PublishDate = publishDate;
|
||||
}
|
||||
|
||||
public User Author
|
||||
{
|
||||
get => author;
|
||||
set => author = value;
|
||||
}
|
||||
public string Description
|
||||
{
|
||||
get => description;
|
||||
set => description = value;
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
get => title;
|
||||
set => title = value;
|
||||
}
|
||||
public DateTime PublishDate
|
||||
{
|
||||
get => publishDate;
|
||||
set => publishDate = value;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StudentHouseDashboard.Models
|
||||
{
|
||||
public interface IMessage
|
||||
{
|
||||
string Title { get; set; }
|
||||
string Description { get; set; }
|
||||
User Author { get; set; }
|
||||
DateTime PublishDate { get; set; }
|
||||
}
|
||||
}
|
@@ -7,7 +7,13 @@ namespace StudentHouseDashboard.Models
|
||||
{
|
||||
public interface IVotable
|
||||
{
|
||||
void UpVote();
|
||||
void DownVote();
|
||||
void UpVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
void DownVote()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -7,20 +8,42 @@ namespace StudentHouseDashboard.Models
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public User(int username, UserRole role)
|
||||
private int id;
|
||||
private string name;
|
||||
private string password;
|
||||
private UserRole role;
|
||||
|
||||
public User(int id, string name, string password, UserRole role)
|
||||
{
|
||||
Username = username;
|
||||
Id = id;
|
||||
Name = name;
|
||||
Password = password;
|
||||
Role = role;
|
||||
}
|
||||
|
||||
public int Username
|
||||
public User()
|
||||
{
|
||||
get;set;
|
||||
|
||||
}
|
||||
public int Id
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => name = value;
|
||||
}
|
||||
[PasswordPropertyText(true)]
|
||||
public string Password
|
||||
{
|
||||
get => password;
|
||||
set => password = value;
|
||||
}
|
||||
public UserRole Role
|
||||
{
|
||||
get;set;
|
||||
get => role;
|
||||
set => role = value;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
using StudentHouseDashboard.Managers;
|
||||
using StudentHouseDashboard.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StudentHouseDashboard.Repositories
|
||||
{
|
||||
public class AnnouncementRepository
|
||||
{
|
||||
private string connectionString = "Server=mssqlstud.fhict.local;Database=dbi509645;User Id=dbi509645;Password=sNPNBm*BX!6z8RM;";
|
||||
public AnnouncementRepository() { }
|
||||
private SqlConnection CreateConnection()
|
||||
{
|
||||
SqlConnection connection = new SqlConnection(connectionString);
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Console.WriteLine("Database connection error. Are you connected to the VDI VPN?");
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
public List<Announcement> GetAllAnnouncements()
|
||||
{
|
||||
var announcements = new List<Announcement>();
|
||||
UserManager userManager = new UserManager();
|
||||
using (SqlConnection conn = CreateConnection())
|
||||
{
|
||||
string sql = "SELECT * FROM Announcements;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
var reader = cmd.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
// ID, Name, Password, Role
|
||||
announcements.Add(new Announcement(userManager.GetUserById(Convert.ToInt32(reader["ID"])),
|
||||
reader["Description"].ToString(), reader["Title"].ToString(),
|
||||
(DateTime)reader["PublishDate"], (bool)reader["IsImportant"],
|
||||
(bool)reader["IsSticky"]));
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
return announcements;
|
||||
}
|
||||
}
|
||||
}
|
127
StudentHouseDashboard/HouseData/Repositories/UserRepository.cs
Normal file
127
StudentHouseDashboard/HouseData/Repositories/UserRepository.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.SqlClient;
|
||||
using StudentHouseDashboard.Models;
|
||||
using System.Data;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StudentHouseDashboard.Repositories
|
||||
{
|
||||
public class UserRepository
|
||||
{
|
||||
private string connectionString = "Server=mssqlstud.fhict.local;Database=dbi509645;User Id=dbi509645;Password=sNPNBm*BX!6z8RM;";
|
||||
|
||||
public UserRepository() { }
|
||||
private SqlConnection CreateConnection()
|
||||
{
|
||||
SqlConnection connection = new SqlConnection(connectionString);
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Console.WriteLine("Database connection error. Are you connected to the VDI VPN?");
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
public List<User> GetAllUsers()
|
||||
{
|
||||
var users = new List<User>();
|
||||
|
||||
using (SqlConnection conn = CreateConnection())
|
||||
{
|
||||
string sql = "SELECT * FROM Users;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
var reader = cmd.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
// ID, Name, Password, Role
|
||||
users.Add(new User(Convert.ToInt32(reader["ID"]),
|
||||
reader["Name"].ToString(),
|
||||
reader["Password"].ToString(),
|
||||
(UserRole)reader["Role"])
|
||||
);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
return users;
|
||||
}
|
||||
public User GetUserById(int id)
|
||||
{
|
||||
using (SqlConnection conn = CreateConnection())
|
||||
{
|
||||
string sql = "SELECT * FROM Users WHERE ID = @id;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
var reader = cmd.ExecuteReader();
|
||||
|
||||
reader.Read();
|
||||
// ID, Name, Password, Role
|
||||
return new User(Convert.ToInt32(reader["ID"]),
|
||||
reader["Name"].ToString(),
|
||||
reader["Password"].ToString(),
|
||||
(UserRole)reader["Role"]);
|
||||
}
|
||||
}
|
||||
public bool CreateUser(string name, string password, UserRole role)
|
||||
{
|
||||
using (SqlConnection conn = CreateConnection())
|
||||
{
|
||||
string sql = "INSERT INTO Users (Name, Password, Role) VALUES (@name, @pass, @role);";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("@name", name);
|
||||
cmd.Parameters.AddWithValue("@pass", password);
|
||||
cmd.Parameters.AddWithValue("@role", (int)role);
|
||||
int writer = cmd.ExecuteNonQuery();
|
||||
if (writer == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
public bool UpdateUser(int id, string name, string password, UserRole role)
|
||||
{
|
||||
using (SqlConnection conn = CreateConnection())
|
||||
{
|
||||
string sql = "UPDATE Users " +
|
||||
"SET Name = @name, Password = @pass, Role = @role " +
|
||||
"WHERE ID = @id;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("@name", name);
|
||||
cmd.Parameters.AddWithValue("@pass", password);
|
||||
cmd.Parameters.AddWithValue("@role", (int)role);
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
int writer = cmd.ExecuteNonQuery();
|
||||
if (writer == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
public bool DisableUser(int id)
|
||||
{
|
||||
using (SqlConnection conn = CreateConnection())
|
||||
{
|
||||
string sql = "UPDATE Users " +
|
||||
"SET Name = 'Deleted User @id', Password = '0', Role = @role " +
|
||||
"WHERE ID = @id;";
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
int writer = cmd.ExecuteNonQuery();
|
||||
if (writer == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
4
StudentHouseDashboard/WebApp/Pages/Announcement.cshtml
Normal file
4
StudentHouseDashboard/WebApp/Pages/Announcement.cshtml
Normal file
@@ -0,0 +1,4 @@
|
||||
@page
|
||||
@model WebApp.Pages.AnnouncementModel
|
||||
@{
|
||||
}
|
12
StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs
Normal file
12
StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class AnnouncementModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
15
StudentHouseDashboard/WebApp/Pages/Announcements.cshtml
Normal file
15
StudentHouseDashboard/WebApp/Pages/Announcements.cshtml
Normal file
@@ -0,0 +1,15 @@
|
||||
@page
|
||||
@model WebApp.Pages.AnnouncementsModel
|
||||
@{
|
||||
ViewData["Title"] = "Announcements";
|
||||
}
|
||||
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Card title</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
|
||||
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
|
||||
<a href="#" class="card-link">Card link</a>
|
||||
<a href="#" class="card-link">Another link</a>
|
||||
</div>
|
||||
</div>
|
12
StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs
Normal file
12
StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class AnnouncementsModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
26
StudentHouseDashboard/WebApp/Pages/Login.cshtml
Normal file
26
StudentHouseDashboard/WebApp/Pages/Login.cshtml
Normal file
@@ -0,0 +1,26 @@
|
||||
@page
|
||||
@model WebApp.Pages.LoginModel
|
||||
@{
|
||||
ViewData["Title"] = "Login";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
@if (ViewData["confirm"] != null)
|
||||
{
|
||||
<div class="alert alert-primary" role="alert">
|
||||
@ViewData["confirm"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Name" class="form-label">Name: </label>
|
||||
<input asp-for="MyUser.Name" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Password" class="form-label">Password: </label>
|
||||
<input asp-for="MyUser.Password" class="form-control" />
|
||||
</div>
|
||||
<input type="submit" value="Submit" class="btn btn-primary" />
|
||||
</form>
|
32
StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs
Normal file
32
StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using StudentHouseDashboard.Models;
|
||||
using StudentHouseDashboard.Managers;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class LoginModel : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public User MyUser { get; set; }
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPost()
|
||||
{
|
||||
var userManager = new UserManager();
|
||||
|
||||
foreach (var item in userManager.GetAllUsers())
|
||||
{
|
||||
if (item.Name == MyUser.Name && BCrypt.Net.BCrypt.Verify(MyUser.Password, item.Password))
|
||||
{
|
||||
MyUser = item;
|
||||
ViewData["confirm"] = $"Welcome, {MyUser.Name}! {MyUser.Id}, {MyUser.Password}, {MyUser.Role}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
30
StudentHouseDashboard/WebApp/Pages/Register.cshtml
Normal file
30
StudentHouseDashboard/WebApp/Pages/Register.cshtml
Normal file
@@ -0,0 +1,30 @@
|
||||
@page
|
||||
@model WebApp.Pages.RegisterModel
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
@if (ViewData["confirm"] != null)
|
||||
{
|
||||
<div class="alert alert-primary" role="alert">
|
||||
@ViewData["confirm"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Role" class="form-label">Role: </label>
|
||||
<input asp-for="MyUser.Role" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Name" class="form-label">Name: </label>
|
||||
<input asp-for="MyUser.Name" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Password" class="form-label">Password: </label>
|
||||
<input asp-for="MyUser.Password" class="form-control" />
|
||||
</div>
|
||||
<input type="submit" value="Submit" class="btn btn-primary" />
|
||||
</form>
|
24
StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs
Normal file
24
StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using StudentHouseDashboard.Managers;
|
||||
using StudentHouseDashboard.Models;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class RegisterModel : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public User MyUser { get; set; }
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
public void OnPost()
|
||||
{
|
||||
var userManager = new UserManager();
|
||||
if (userManager.CreateUser(MyUser.Name, BCrypt.Net.BCrypt.HashPassword(MyUser.Password), MyUser.Role))
|
||||
{
|
||||
ViewData["confirm"] = $"Successfully registered {MyUser.Name}!";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - WebApp</title>
|
||||
<title>@ViewData["Title"] - StudentHouseDashboard</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/WebApp.styles.css" asp-append-version="true" />
|
||||
@@ -12,7 +12,7 @@
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">WebApp</a>
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">StudentHouseDashboard</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
@@ -28,6 +28,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Contact">Contact</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Login">Login</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -41,7 +44,7 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2023 - WebApp - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
© 2023 - StudentHouseDashboard - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
@@ -25,4 +25,12 @@
|
||||
<_ContentIncludedByDefault Remove="Pages\Contact.cshtml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HouseData\StudentHouseDashboard.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Binary file not shown.
18
queries.sql
Normal file
18
queries.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
USE dbi509645
|
||||
GO
|
||||
|
||||
INSERT INTO UserRole ([Role])
|
||||
VALUES
|
||||
('TENANT'),
|
||||
('MANAGER'),
|
||||
('ADMIN')
|
||||
GO
|
||||
|
||||
INSERT INTO Users ([Name], [Password], [Role])
|
||||
VALUES
|
||||
('Admin', '1234', 2),
|
||||
('Manager', '1234', 1),
|
||||
('Room1', '1234', 0)
|
||||
GO
|
||||
|
||||
SELECT * FROM Users u JOIN UserRole r ON u.[Role] = r.ID
|
55
table.sql
Normal file
55
table.sql
Normal file
@@ -0,0 +1,55 @@
|
||||
USE dbi509645
|
||||
GO
|
||||
|
||||
CREATE TABLE UserRole (
|
||||
ID INT PRIMARY KEY IDENTITY(0,1) NOT NULL,
|
||||
[Role] NVARCHAR(255)
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE Users (
|
||||
ID INT PRIMARY KEY IDENTITY NOT NULL,
|
||||
[Name] NVARCHAR(255) NOT NULL,
|
||||
[Password] NVARCHAR(4000) NOT NULL,
|
||||
[Role] INT FOREIGN KEY REFERENCES UserRole(ID) NOT NULL
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE ContactForm (
|
||||
ID INT PRIMARY KEY IDENTITY NOT NULL,
|
||||
[Name] NVARCHAR(255) NOT NULL,
|
||||
Email NVARCHAR(255) NOT NULL
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE Announcements (
|
||||
ID INT PRIMARY KEY IDENTITY NOT NULL,
|
||||
[Author] INT FOREIGN KEY REFERENCES Users(ID) NOT NULL,
|
||||
[Description] NVARCHAR(MAX),
|
||||
[Title] NVARCHAR(255) NOT NULL,
|
||||
[PublishDate] DATETIME NOT NULL,
|
||||
[IsImportant] BIT NOT NULL,
|
||||
[IsSticky] BIT NOT NULL,
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE Comments (
|
||||
ID INT PRIMARY KEY IDENTITY NOT NULL,
|
||||
[Author] INT FOREIGN KEY REFERENCES Users(ID) NOT NULL,
|
||||
[Description] NVARCHAR(MAX) NOT NULL,
|
||||
[Title] NVARCHAR(255) NOT NULL,
|
||||
[PublishDate] DATETIME NOT NULL
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE AnnouncementsComments (
|
||||
AnnouncementID INT FOREIGN KEY REFERENCES Announcements(ID) NOT NULL,
|
||||
CommentID INT FOREIGN KEY REFERENCES Comments(ID) NOT NULL
|
||||
)
|
||||
GO
|
||||
|
||||
CREATE TABLE CommentsResponses (
|
||||
CommentID INT FOREIGN KEY REFERENCES Comments(ID) NOT NULL,
|
||||
ResponseID INT FOREIGN KEY REFERENCES Comments(ID) NOT NULL
|
||||
)
|
||||
GO
|
Reference in New Issue
Block a user