diff --git a/.vs/ENEI2019/v15/.suo b/.vs/ENEI2019/v15/.suo new file mode 100644 index 00000000..03597dd9 Binary files /dev/null and b/.vs/ENEI2019/v15/.suo differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 00000000..6b611411 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,6 @@ +{ + "ExpandedNodes": [ + "" + ], + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 00000000..7a96e85f Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/api/Controllers/TeamsController.cs b/api/Controllers/TeamsController.cs new file mode 100644 index 00000000..639af5df --- /dev/null +++ b/api/Controllers/TeamsController.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; +using System.Threading.Tasks; +using api.Data; +using api.Dtos; +using api.Models; +using AutoMapper; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; + +namespace api.Controllers +{ + [Authorize] + [Route("api/[controller]")] + [ApiController] + + public class TeamsController : ControllerBase + { + + private readonly ITeamsRepository _repo; + private readonly IMapper _mapper; + private readonly UserManager _userManager; + private readonly DataContext _context; + + public TeamsController(DataContext context, ITeamsRepository repo, IMapper mapper,UserManager userManager) + { + _context = context; + _userManager = userManager; + _repo = repo; + _mapper = mapper; + } + + [Authorize] + [HttpGet] + public async Task GetTeams() + { + var result = await _repo.GetTeams(); + + return Ok(result); + } + } +} \ No newline at end of file diff --git a/api/Data/DataContext.cs b/api/Data/DataContext.cs index 43d1c208..d1244135 100755 --- a/api/Data/DataContext.cs +++ b/api/Data/DataContext.cs @@ -14,6 +14,7 @@ namespace api.Data public DbSet Photos {get;set;} + public DbSet Teams {get;set;} protected override void OnModelCreating(ModelBuilder builder) diff --git a/api/Data/ITeamsRepository.cs b/api/Data/ITeamsRepository.cs new file mode 100644 index 00000000..5dcada65 --- /dev/null +++ b/api/Data/ITeamsRepository.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using api.Models; + +namespace api.Data +{ + + public interface ITeamsRepository + { + Task> GetTeams(); + } + +} \ No newline at end of file diff --git a/api/Data/TeamsRepository.cs b/api/Data/TeamsRepository.cs new file mode 100644 index 00000000..40e8304d --- /dev/null +++ b/api/Data/TeamsRepository.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using api.Models; +using Microsoft.EntityFrameworkCore; + +namespace api.Data +{ + public class TeamsRepository : ITeamsRepository + { + private readonly DataContext _context; + + public TeamsRepository(DataContext context) + { + this._context = context; + } + public async Task> GetTeams() + { + var teams = await _context.Teams.ToListAsync(); + + return teams; + } + } +} \ No newline at end of file diff --git a/api/Migrations/20190214165735_teams.Designer.cs b/api/Migrations/20190214165735_teams.Designer.cs new file mode 100644 index 00000000..38655693 --- /dev/null +++ b/api/Migrations/20190214165735_teams.Designer.cs @@ -0,0 +1,365 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using api.Data; + +namespace api.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20190214165735_teams")] + partial class teams + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.1.4-rtm-31024"); + + modelBuilder.Entity("api.Models.EventQR", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Event"); + + b.Property("EventLocId"); + + b.Property("Pontos"); + + b.Property("QRData"); + + b.Property("TeamId"); + + b.Property("TimeGen"); + + b.HasKey("Id"); + + b.HasIndex("TeamId"); + + b.ToTable("EventQR"); + }); + + modelBuilder.Entity("api.Models.Photo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateAdded"); + + b.Property("Description"); + + b.Property("IsMain"); + + b.Property("Url"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Photos"); + }); + + modelBuilder.Entity("api.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("api.Models.Team", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Event"); + + b.Property("Nome"); + + b.Property("NumMemb"); + + b.Property("Pontos"); + + b.Property("VisitedNum"); + + b.HasKey("Id"); + + b.ToTable("Teams"); + }); + + modelBuilder.Entity("api.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("About"); + + b.Property("AccessFailedCount"); + + b.Property("Adress"); + + b.Property("Age"); + + b.Property("City"); + + b.Property("Company"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Country"); + + b.Property("Degree"); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("FullName"); + + b.Property("Gender"); + + b.Property("LastLogin"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("Phone"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("Position"); + + b.Property("ProfileIcon"); + + b.Property("QRcode"); + + b.Property("Registed"); + + b.Property("Role"); + + b.Property("SchoolYear"); + + b.Property("SecurityStamp"); + + b.Property("TeamId"); + + b.Property("TwoFactorEnabled"); + + b.Property("University"); + + b.Property("UserName") + .HasMaxLength(256); + + b.Property("linkedIn"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.HasIndex("TeamId"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("api.Models.UserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("api.Models.Value", b => + { + b.Property("id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.HasKey("id"); + + b.ToTable("Values"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("api.Models.EventQR", b => + { + b.HasOne("api.Models.Team") + .WithMany("QRs") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("api.Models.Photo", b => + { + b.HasOne("api.Models.User", "User") + .WithMany("Photos") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("api.Models.User", b => + { + b.HasOne("api.Models.Team") + .WithMany("Users") + .HasForeignKey("TeamId"); + }); + + modelBuilder.Entity("api.Models.UserRole", b => + { + b.HasOne("api.Models.Role", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("api.Models.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("api.Models.Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("api.Models.User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("api.Models.User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("api.Models.User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/api/Migrations/20190214165735_teams.cs b/api/Migrations/20190214165735_teams.cs new file mode 100644 index 00000000..0e335ae2 --- /dev/null +++ b/api/Migrations/20190214165735_teams.cs @@ -0,0 +1,96 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace api.Migrations +{ + public partial class teams : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "TeamId", + table: "AspNetUsers", + nullable: true); + + migrationBuilder.CreateTable( + name: "Teams", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Nome = table.Column(nullable: true), + Event = table.Column(nullable: false), + NumMemb = table.Column(nullable: false), + VisitedNum = table.Column(nullable: false), + Pontos = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Teams", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "EventQR", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Event = table.Column(nullable: false), + TeamId = table.Column(nullable: false), + EventLocId = table.Column(nullable: false), + Pontos = table.Column(nullable: false), + TimeGen = table.Column(nullable: false), + QRData = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_EventQR", x => x.Id); + table.ForeignKey( + name: "FK_EventQR_Teams_TeamId", + column: x => x.TeamId, + principalTable: "Teams", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUsers_TeamId", + table: "AspNetUsers", + column: "TeamId"); + + migrationBuilder.CreateIndex( + name: "IX_EventQR_TeamId", + table: "EventQR", + column: "TeamId"); + + migrationBuilder.AddForeignKey( + name: "FK_AspNetUsers_Teams_TeamId", + table: "AspNetUsers", + column: "TeamId", + principalTable: "Teams", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AspNetUsers_Teams_TeamId", + table: "AspNetUsers"); + + migrationBuilder.DropTable( + name: "EventQR"); + + migrationBuilder.DropTable( + name: "Teams"); + + migrationBuilder.DropIndex( + name: "IX_AspNetUsers_TeamId", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "TeamId", + table: "AspNetUsers"); + } + } +} diff --git a/api/Migrations/DataContextModelSnapshot.cs b/api/Migrations/DataContextModelSnapshot.cs index 969d2571..bd11d6b2 100755 --- a/api/Migrations/DataContextModelSnapshot.cs +++ b/api/Migrations/DataContextModelSnapshot.cs @@ -14,7 +14,31 @@ namespace api.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.1.1-rtm-30846"); + .HasAnnotation("ProductVersion", "2.1.4-rtm-31024"); + + modelBuilder.Entity("api.Models.EventQR", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Event"); + + b.Property("EventLocId"); + + b.Property("Pontos"); + + b.Property("QRData"); + + b.Property("TeamId"); + + b.Property("TimeGen"); + + b.HasKey("Id"); + + b.HasIndex("TeamId"); + + b.ToTable("EventQR"); + }); modelBuilder.Entity("api.Models.Photo", b => { @@ -61,6 +85,26 @@ namespace api.Migrations b.ToTable("AspNetRoles"); }); + modelBuilder.Entity("api.Models.Team", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Event"); + + b.Property("Nome"); + + b.Property("NumMemb"); + + b.Property("Pontos"); + + b.Property("VisitedNum"); + + b.HasKey("Id"); + + b.ToTable("Teams"); + }); + modelBuilder.Entity("api.Models.User", b => { b.Property("Id") @@ -128,6 +172,8 @@ namespace api.Migrations b.Property("SecurityStamp"); + b.Property("TeamId"); + b.Property("TwoFactorEnabled"); b.Property("University"); @@ -146,6 +192,8 @@ namespace api.Migrations .IsUnique() .HasName("UserNameIndex"); + b.HasIndex("TeamId"); + b.ToTable("AspNetUsers"); }); @@ -242,6 +290,14 @@ namespace api.Migrations b.ToTable("AspNetUserTokens"); }); + modelBuilder.Entity("api.Models.EventQR", b => + { + b.HasOne("api.Models.Team") + .WithMany("QRs") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade); + }); + modelBuilder.Entity("api.Models.Photo", b => { b.HasOne("api.Models.User", "User") @@ -250,6 +306,13 @@ namespace api.Migrations .OnDelete(DeleteBehavior.Cascade); }); + modelBuilder.Entity("api.Models.User", b => + { + b.HasOne("api.Models.Team") + .WithMany("Users") + .HasForeignKey("TeamId"); + }); + modelBuilder.Entity("api.Models.UserRole", b => { b.HasOne("api.Models.Role", "Role") diff --git a/api/Models/Event.cs b/api/Models/Event.cs index 9f305738..e3890116 100755 --- a/api/Models/Event.cs +++ b/api/Models/Event.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace api.Models @@ -8,5 +9,7 @@ namespace api.Models public int Id{get;set;} public string Nome{get;set;} public string Desc{get;set;} + public ICollection Locations{get;set;} + } } \ No newline at end of file diff --git a/api/Models/EventLocVisited.cs b/api/Models/EventLocVisited.cs index 5bb8f0e4..d09430ee 100755 --- a/api/Models/EventLocVisited.cs +++ b/api/Models/EventLocVisited.cs @@ -8,7 +8,7 @@ namespace api.Models public int Id{get;set;} public int Event{get;set;} public int TeamId{get;set;} - public int UserId{get;set;} + public String UserQR{get;set;} public int QRId{get;set;} public DateTime Time{get;set;} diff --git a/api/Models/Team.cs b/api/Models/Team.cs index e31cb2b0..fa1b1daa 100755 --- a/api/Models/Team.cs +++ b/api/Models/Team.cs @@ -11,7 +11,7 @@ namespace api.Models public string Nome{get;set;} public int Event{get;set;} - public ICollection Users{get;set;} + public ICollection Users{get;set;} public int NumMemb{get;set;} public int VisitedNum{get;set;} diff --git a/api/Startup.cs b/api/Startup.cs index 91e634c6..52012bcf 100755 --- a/api/Startup.cs +++ b/api/Startup.cs @@ -24,6 +24,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; +using Pomelo.EntityFrameworkCore.MySql; namespace api { @@ -46,7 +47,7 @@ namespace api services.AddScoped(); //define a connection string indicada em appsettings.json - services.AddDbContext(x=>x.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))); + services.AddDbContext(x=>x.UseMySql(Configuration.GetConnectionString("DefaultConnection"))); IdentityBuilder builder = services.AddIdentityCore(Options=> { diff --git a/api/api.csproj b/api/api.csproj index d662af91..edf9c949 100755 --- a/api/api.csproj +++ b/api/api.csproj @@ -3,11 +3,12 @@ netcoreapp2.1 - + - - - + + + + \ No newline at end of file diff --git a/api/appsettings.json b/api/appsettings.json index 41669945..0fcc572a 100755 --- a/api/appsettings.json +++ b/api/appsettings.json @@ -5,7 +5,7 @@ }, "ConnectionStrings": { - "DefaultConnection":"Data Source= api.db" + "DefaultConnection":"server=enei.zmiguel.me;port=3306;database=enei;uid=enei;password=ENEIMegaPassword!" }, "Logging": { diff --git a/api/obj/Debug/netcoreapp2.1/api.assets.cache b/api/obj/Debug/netcoreapp2.1/api.assets.cache new file mode 100644 index 00000000..e445080c Binary files /dev/null and b/api/obj/Debug/netcoreapp2.1/api.assets.cache differ diff --git a/api/obj/Debug/netcoreapp2.1/project.razor.json b/api/obj/Debug/netcoreapp2.1/project.razor.json new file mode 100644 index 00000000..2ba5fb94 --- /dev/null +++ b/api/obj/Debug/netcoreapp2.1/project.razor.json @@ -0,0 +1,14 @@ +{ + "ProjectFilePath": "c:\\Users\\ZMiguel\\Desktop\\ENEI2019\\api\\api.csproj", + "TargetFramework": "netcoreapp2.1", + "TagHelpers": [], + "Configuration": { + "ConfigurationName": "MVC-2.1", + "LanguageVersion": "2.1", + "Extensions": [ + { + "ExtensionName": "MVC-2.1" + } + ] + } +} \ No newline at end of file