Skip to content

Instantly share code, notes, and snippets.

@gzamudio
gzamudio / tasks.json
Created October 9, 2019 19:33
Tasks json file for .NET Core apps
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/{appPath}/{appName}.csproj",
@gzamudio
gzamudio / launch.json
Created October 9, 2019 19:31
VS Code launch file for .NET Core apps.
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/{appPath}/{appName}.dll",
"args": [],
@gzamudio
gzamudio / AccountApiController.cs
Created May 15, 2019 20:03
Email confirmation
namespace NetCoreBootstrap.Api.V1.Controllers
{
[Route("/api/v1/[controller]/[action]")]
public class AccountApiController : Controller
{
...
[HttpPost("SignIn")]
public async Task<object> SignIn([FromBody] UserVO userValueObject)
{
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[HttpGet("AllResourceCategoryMetric")]
public IActionResult ResourceCategoryMetric(string startingDate)
{
// TODO: roles not implemented yed, this metric is returns the same metric for any role
if (startingDate == string.Empty)
return BadRequest(Localizer["SelectATimePeriod"]);
var resources = UnitOfWork.ResourceRepository.GetAllWithRelatedEntitites().Where(ra =>
ra.UpdatedAt >= DateTime.ParseExact(startingDate, "dd/MM/yyyy", CultureInfo.InvariantCulture))
.ToList();
private IEnumerable<Resource> GetSchoolGroupAccesedResources(int? schoolId, SchoolGroup schoolGroup, DateTime startingDate)
{
var schoolGroupResources = schoolGroup
.SchoolGroupPrograms
.SelectMany(sgp => sgp.EducationalProgram.EducationalProgramResources)
.Select(epr => epr.Resource)
.Where(r => r.UpdatedAt > startingDate);
IEnumerable<int> schoolUserIds = null;
if (schooId != null)
schoolUserIds = school.Teachers.Select(t => t.TeacherId).Concat(school.Managers.Select(m => m.ManagerId);
public async Task<IActionResult> CategoryMetric(string startingDate, int? schoolId)
{
var currentUser = (await UserManager.FindByEmailAsync(User.Identity.Name));
try
{
if (GetSchoolToSearch(currentUser, schoolId) == null && !currentUser.IsInRole("Admin"))
return BadRequest(Localizer["UserIsNotSchoolGroupAdmin"]);
return Ok(GetSchoolGroupAccesedResources(schoolId,
currentUser.SchoolGroup, DateTime.ParseExact(startingDate,
"dd/MM/yyyy",
using System;
using System.Collections.Generic;
using System.Linq;
using EduitorNetCore.Models.Database;
using EduitorNetCore.Models.VOs.Reduceds;
using EduitorNetCore.Repositories.Database;
using EduitorNetCore.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace EduitorNetCore.Repositories
@gzamudio
gzamudio / Repository.cs
Last active December 18, 2018 18:00
Dapper
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Project.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace Project.Repositories
{
public class Repository<T> : IRepository<T> where T : class
@gzamudio
gzamudio / Repository.cs
Last active December 18, 2018 18:00
EF Core
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Project.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace Project.Repositories
{
public class Repository<T> : IRepository<T> where T : class
var keywords = new List<Tuple<int, string>>();
foreach(var obj in response)
{
var tuple = new Tuple<int, string>(Convert.ToInt32(obj), obj.ToString());
keywords.Add(tuple);
}