Ejemplo n.º 1
0
            public async Task <ApiResponse <Result> > Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await heroContext.Users.Where(u => u.Id == request.UserId)
                           .Include(inc => inc.MyOngs)
                           .FirstOrDefaultAsync();

                if (user == null)
                {
                    return(ApiResponse <Result> .FailureFrom("User not found"));
                }

                var ong = user.MyOngs.FirstOrDefault();

                var incident = mapper.Map <Domain.Incident>(request);

                incident.Ong = ong;

                heroContext.Add(incident);

                return(ApiResponse <Result> .SuccessFrom(new Result()
                {
                    Id = incident.Id,
                }));
            }
 /// <summary>
 /// Metodo para inclusao de Heroís na Base de Dados
 /// </summary>
 /// <param name="hero"></param>
 /// <returns></returns>
 public void Insert(Hero hero)
 {
     _context.Add(hero);
 }
 public void Add <T>(T Entity) where T : class
 {
     _context.Add(Entity);
 }