diff --git a/api/Controllers/AuthController.cs b/api/Controllers/AuthController.cs index 527fb2b2..94f95a04 100755 --- a/api/Controllers/AuthController.cs +++ b/api/Controllers/AuthController.cs @@ -28,7 +28,6 @@ namespace api.Controllers public UserManager _userManager { get; } public SignInManager _signInManager { get; } public IUsersRepository _repo { get; } - private readonly IMapper _mapper; private readonly RoleManager _roleManager; diff --git a/api/Controllers/EventsController.cs b/api/Controllers/EventsController.cs new file mode 100644 index 00000000..7383d0db --- /dev/null +++ b/api/Controllers/EventsController.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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; + +namespace api.Controllers +{ + + [Authorize] + [Route("api/[controller]")] + [ApiController] + public class EventsController : ControllerBase + { + private readonly DataContext context; + private readonly IEventsRepository _repo; + private readonly IMapper _mapper; + public EventsController(DataContext context,IEventsRepository repo, IMapper mapper) + { + this.context = context; + _mapper = mapper; + _repo = repo; + } + + // GET api/events + // GET all events + [HttpGet] + public async Task GetEvents() + { + var Events = await _repo.GetEvents(); + return Ok(Events); + } + + // GET api/events/[id] + // GET events id x + [HttpGet("{id}")] + public async Task GetEvent(int id) + { + var Event = await _repo.GetEvent(id); + return Ok(Event); + } + } +} diff --git a/api/Controllers/TeamsController.cs b/api/Controllers/TeamsController.cs index e5598d92..6ed8fb1e 100644 --- a/api/Controllers/TeamsController.cs +++ b/api/Controllers/TeamsController.cs @@ -34,11 +34,12 @@ namespace api.Controllers } // GET api/teams + // GET all teams [HttpGet] public async Task GetTeams() { - var values= await context.Values.ToListAsync(); - return Ok(values); + var Teams = await context.Teams.ToArrayAsync(); + return Ok(Teams); } } } diff --git a/api/Data/DataContext.cs b/api/Data/DataContext.cs index 2b4d4713..e6ac56e1 100755 --- a/api/Data/DataContext.cs +++ b/api/Data/DataContext.cs @@ -5,8 +5,8 @@ using Microsoft.EntityFrameworkCore; namespace api.Data { - public class DataContext : IdentityDbContext, - UserRole,IdentityUserLogin,IdentityRoleClaim,IdentityUserToken> + public class DataContext : IdentityDbContext,UserRole,IdentityUserLogin, + IdentityRoleClaim,IdentityUserToken> { public DataContext(DbContextOptions options):base(options) { } @@ -24,31 +24,31 @@ namespace api.Data public DbSetLogs{get;set;} -public DbSetProducts{get;set;} + public DbSetProducts{get;set;} - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); - //para o ef saber as relações - builder.Entity(userRole => - { - userRole.HasKey(ur=> new {ur.UserId, ur.RoleId}); + //para o ef saber as relações + builder.Entity(userRole => + { + userRole.HasKey(ur=> new {ur.UserId, ur.RoleId}); - userRole.HasOne( ur=>ur.Role) - .WithMany(r=>r.UserRoles) - .HasForeignKey(ur=> ur.RoleId) - .IsRequired(); + userRole.HasOne( ur=>ur.Role) + .WithMany(r=>r.UserRoles) + .HasForeignKey(ur=> ur.RoleId) + .IsRequired(); - userRole.HasOne( ur=>ur.User) - .WithMany(r=>r.UserRoles) - .HasForeignKey(ur=> ur.UserId) - .IsRequired(); - - }); - } + userRole.HasOne( ur=>ur.User) + .WithMany(r=>r.UserRoles) + .HasForeignKey(ur=> ur.UserId) + .IsRequired(); + + }); + } } } \ No newline at end of file diff --git a/api/Data/EventsRepository.cs b/api/Data/EventsRepository.cs new file mode 100644 index 00000000..a7fb28d8 --- /dev/null +++ b/api/Data/EventsRepository.cs @@ -0,0 +1,34 @@ +using System; +using System.Threading.Tasks; +using api.Models; +using api.Data; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; + +namespace api.Data +{ + public class EventsRepository : IEventsRepository + { + public EventsRepository(DataContext context) + { + _context = context; + } + + public DataContext _context { get; } + + public async Task GetEvent(int id) + { + var Event = await _context.Events.FirstOrDefaultAsync(e=>e.Id == id); + + return Event; + } + + public async Task> GetEvents() + { + var Events = await _context.Events.ToListAsync(); + + return Events; + } + + } +} \ No newline at end of file diff --git a/api/Data/IEventsRepository.cs b/api/Data/IEventsRepository.cs new file mode 100644 index 00000000..79233e7f --- /dev/null +++ b/api/Data/IEventsRepository.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using api.Models; + +namespace api.Data +{ + public interface IEventsRepository + { + + Task> GetEvents(); + Task GetEvent(int id); + + + } +} \ No newline at end of file diff --git a/api/Startup.cs b/api/Startup.cs index 62aee96b..913485cf 100755 --- a/api/Startup.cs +++ b/api/Startup.cs @@ -45,6 +45,7 @@ namespace api services.AddAutoMapper(); services.AddScoped(); + services.AddScoped(); //define a connection string indicada em appsettings.json services.AddDbContext(x=>x.UseMySql(Configuration.GetConnectionString("DefaultConnection"))); diff --git a/api/obj/Debug/netcoreapp2.1/api.assets.cache b/api/obj/Debug/netcoreapp2.1/api.assets.cache index 5e8a8b31..e445080c 100755 Binary files a/api/obj/Debug/netcoreapp2.1/api.assets.cache and b/api/obj/Debug/netcoreapp2.1/api.assets.cache differ