-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7331110
Showing
4,721 changed files
with
282,451 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" /> | ||
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.11" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Breathtaking.Models; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Breathtaking.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
private BreathContext _bContext; | ||
public HomeController(BreathContext context) | ||
{ | ||
_bContext = context; | ||
} | ||
private User ActiveUser | ||
{ | ||
get | ||
{ | ||
return _bContext.users.Where(u => u.user_id == HttpContext.Session.GetInt32("user_id")).FirstOrDefault(); | ||
} | ||
} | ||
[HttpGet("")] | ||
public IActionResult Index() | ||
{ | ||
return View(); | ||
} | ||
[HttpGet("register")] | ||
public IActionResult Register() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpGet("login")] | ||
public IActionResult Login() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpPost("registeruser")] | ||
public IActionResult RegisterUser(RegisterUser newuser) | ||
{ | ||
User CheckEmail = _bContext.users | ||
.Where(u => u.email == newuser.email) | ||
.SingleOrDefault(); | ||
|
||
if(CheckEmail != null) | ||
{ | ||
ViewBag.errors = "That email already exists"; | ||
return RedirectToAction("Register"); | ||
} | ||
if(ModelState.IsValid) | ||
{ | ||
PasswordHasher<RegisterUser> Hasher = new PasswordHasher<RegisterUser>(); | ||
User newUser = new User | ||
{ | ||
user_id = newuser.user_id, | ||
first_name = newuser.first_name, | ||
last_name = newuser.last_name, | ||
email = newuser.email, | ||
password = Hasher.HashPassword(newuser, newuser.password) | ||
}; | ||
_bContext.Add(newUser); | ||
_bContext.SaveChanges(); | ||
ViewBag.success = "Successfully registered"; | ||
return RedirectToAction("Login"); | ||
} | ||
else | ||
{ | ||
return View("Register"); | ||
} | ||
} | ||
|
||
[HttpPost("loginuser")] | ||
public IActionResult LoginUser(LoginUser loginUser) | ||
{ | ||
User CheckEmail = _bContext.users | ||
.SingleOrDefault(u => u.email == loginUser.email); | ||
if(CheckEmail != null) | ||
{ | ||
var Hasher = new PasswordHasher<User>(); | ||
if(0 != Hasher.VerifyHashedPassword(CheckEmail, CheckEmail.password, loginUser.password)) | ||
{ | ||
HttpContext.Session.SetInt32("user_id", CheckEmail.user_id); | ||
HttpContext.Session.SetString("first_name", CheckEmail.first_name); | ||
return RedirectToAction("Index"); | ||
} | ||
else | ||
{ | ||
ViewBag.errors = "Incorrect Password"; | ||
return View("Register"); | ||
} | ||
} | ||
else | ||
{ | ||
ViewBag.errors = "Email not registered"; | ||
return View("Register"); | ||
} | ||
} | ||
|
||
[HttpGet("logout")] | ||
public IActionResult Logout() | ||
{ | ||
HttpContext.Session.Clear(); | ||
return RedirectToAction("Login"); | ||
} | ||
|
||
[HttpGet("About")] | ||
public IActionResult About() | ||
{ | ||
ViewData["Message"] = "Your application description page."; | ||
|
||
return View(); | ||
} | ||
[HttpGet("Gallery")] | ||
public IActionResult Gallery() | ||
{ | ||
ViewData["Message"] = "Your application description page."; | ||
|
||
return View(); | ||
} | ||
[HttpGet("Contact")] | ||
public IActionResult Contact() | ||
{ | ||
ViewData["Message"] = "Your contact page."; | ||
|
||
return View(); | ||
} | ||
[HttpGet("Map")] | ||
public IActionResult Map() | ||
{ | ||
return View(); | ||
} | ||
[HttpGet("Reviews")] | ||
public IActionResult Reviews() | ||
{ | ||
List<Review> reviews = _bContext.reviews.Include(u => u.User).ToList(); | ||
ViewBag.reviews = reviews; | ||
return View(); | ||
} | ||
[HttpPost("AddReview")] | ||
public IActionResult AddReview(Review rev) | ||
{ | ||
if(ActiveUser == null) | ||
{ | ||
return RedirectToAction("Login"); | ||
} | ||
else | ||
{ | ||
if(ModelState.IsValid) | ||
{ | ||
Review newReview = new Review | ||
{ | ||
user_id = ActiveUser.user_id, | ||
rating = rev.rating, | ||
review = rev.review, | ||
start_visit_date = rev.start_visit_date, | ||
end_visit_date = rev.end_visit_date | ||
}; | ||
_bContext.reviews.Add(newReview); | ||
_bContext.SaveChanges(); | ||
return RedirectToAction("Reviews"); | ||
} | ||
return View("Reviews"); | ||
} | ||
} | ||
|
||
public IActionResult Error() | ||
{ | ||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Breathtaking.Models | ||
{ | ||
public class BreathContext : DbContext | ||
{ | ||
// base() calls the parent class' constructor passing the "options" parameter along | ||
public BreathContext(DbContextOptions<BreathContext> options) : base(options) { } | ||
|
||
public DbSet<User> users {get;set;} | ||
public DbSet<Review> reviews {get;set;} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Breathtaking.Models | ||
{ | ||
public class ErrorViewModel | ||
{ | ||
public string RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Breathtaking.Models | ||
{ | ||
public class Review : BaseEntity | ||
{ | ||
[Key] | ||
public int review_id {get;set;} | ||
public int user_id {get;set;} | ||
public User User {get;set;} | ||
[Required] | ||
[Display(Name="Rating")] | ||
public int rating {get;set;} | ||
[Required(ErrorMessage="Review is required")] | ||
[MinLength(5, ErrorMessage="Review has a min length of 5 characters")] | ||
[MaxLength(2000, ErrorMessage="Review has a max length of 2000 characters")] | ||
[Display(Name="Review")] | ||
public string review {get;set;} | ||
[Required] | ||
[DataType(DataType.Date)] | ||
[Display(Name="Start Date")] | ||
public DateTime start_visit_date {get;set;} | ||
[Required] | ||
[DataType(DataType.Date)] | ||
[Display(Name="End Date")] | ||
public DateTime end_visit_date {get;set;} | ||
public Review() | ||
{ | ||
created_at = DateTime.Now; | ||
updated_at = DateTime.Now; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Breathtaking.Models | ||
{ | ||
public class User : BaseEntity | ||
{ | ||
[Key] | ||
public int user_id {get;set;} | ||
public string first_name {get;set;} | ||
public string last_name {get;set;} | ||
public string email {get;set;} | ||
public string password {get;set;} | ||
public List<Review> Reviews {get;set;} | ||
public User() | ||
{ | ||
Reviews = new List<Review>(); | ||
created_at = DateTime.Now; | ||
updated_at = DateTime.Now; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Breathtaking.Models | ||
{ | ||
public abstract class BaseEntity | ||
{ | ||
public DateTime created_at {get;set;} | ||
public DateTime updated_at {get;set;} | ||
} | ||
public class RegisterUser : BaseEntity | ||
{ | ||
[Key] | ||
public int user_id {get;set;} | ||
|
||
[Required(ErrorMessage="First Name is required")] | ||
[MinLength(2, ErrorMessage="A minimum of 2 is allowed for first name")] | ||
[MaxLength(30, ErrorMessage="A maximum of 30 is allowed for first name")] | ||
[RegularExpression(@"^[a-zA-Z]+$", ErrorMessage="Your first name must only contain letters")] | ||
[Display(Name="First Name")] | ||
public string first_name {get;set;} | ||
|
||
[Required(ErrorMessage="Last name is required")] | ||
[MinLength(2, ErrorMessage="A minimum of 2 is allowed for last name")] | ||
[MaxLength(30, ErrorMessage="A maximum of 30 is allowed for last name")] | ||
[RegularExpression(@"^[a-zA-Z]+$", ErrorMessage="Your last name must only contain letters")] | ||
[Display(Name="Last Name")] | ||
public string last_name {get;set;} | ||
|
||
[Required(ErrorMessage="Email is required")] | ||
[EmailAddress] | ||
[DataType(DataType.EmailAddress)] | ||
[Display(Name="Email")] | ||
public string email {get;set;} | ||
|
||
[Required(ErrorMessage="Password is required")] | ||
[MinLength(4, ErrorMessage="A minimum length of 4")] | ||
[MaxLength(20, ErrorMessage="A maximum length of 20")] | ||
[DataType(DataType.Password)] | ||
[Display(Name="Password")] | ||
public string password {get;set;} | ||
|
||
[Required(ErrorMessage="Confirm password is required")] | ||
[DataType(DataType.Password)] | ||
[Compare("password")] | ||
[Display(Name="Confirm Password")] | ||
public string confirm {get;set;} | ||
} | ||
|
||
public class LoginUser : BaseEntity | ||
{ | ||
[Required(ErrorMessage="Email is required")] | ||
[EmailAddress(ErrorMessage="This is an email field")] | ||
[DataType(DataType.EmailAddress)] | ||
[Display(Name="Email")] | ||
public string email {get;set;} | ||
|
||
[Required(ErrorMessage="Password is required")] | ||
[MinLength(4, ErrorMessage="A minimum length of 4")] | ||
[MaxLength(20, ErrorMessage="A maximum length of 20")] | ||
[DataType(DataType.Password)] | ||
[Display(Name="Password")] | ||
|
||
public string password {get;set;} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Breathtaking | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
BuildWebHost(args).Run(); | ||
} | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.Build(); | ||
} | ||
} |
Oops, something went wrong.