Skip to content

Instantly share code, notes, and snippets.

@gzamudio
gzamudio / comandosgit
Last active August 31, 2018 19:16
Comandos git
1) Crear una branch nueva desde branch base
git checkout branchBase (para pararse en la branch deseada)
git checkout -b branchNueva (para crear la nueva a partir de la base)
2) Subir cambios al branch remoto
git add . (Agrega todos los cambios en el local)
*También, si no estás todavía muy cómodo con git podes usar el siguiente comando:
git add -p (este te permite ver lo que vas a agregar)
git commit -m "Mensaje” (genera un paquete con los cambios para enviar al remoto)
git push origin branchNombre (envia el contenido del commit al branch remoto)
@gzamudio
gzamudio / RoutingController.cs
Last active August 31, 2018 19:51
Example Controller (Routing)
[Route("[controller]")]
public class RoutingController : Controller
{
private readonly IUnitOfWork _unitOfWork;
private readonly IHtmlLocalizer<RoutingController> _localizer;
public RoutingController(IUnitOfWork unitOfWork, IHtmlLocalizer<RoutingController> localizer)
{
this._unitOfWork = unitOfWork;
this._localizer = localizer;
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);
}
@gzamudio
gzamudio / linqquery.cs
Last active December 18, 2018 17:16
LINQ Query
var keywords = response.Select(obj =>
new Tuple<int,string>(Convert.ToInt32(obj), obj.ToString())
);
@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
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
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",
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);
[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();