Exemplo n.º 1
0
        public static SponsorDTO ConvertToDTO(this Sponsor model, IMapper _mapper)
        {
            SponsorDTO sponsor = _mapper.Map <Sponsor, SponsorDTO>(model);

            sponsor.Projects = model.Projects.Select(p => p.ConvertToBaseOnly(_mapper)).ToList();
            return(sponsor);
        }
 public async Task <ActionResult <SponsorDTO> > AddSponsor(SponsorDTO sponsor)
 {
     try{
         return(new OkObjectResult(await _sponsorService.AddSponsor(sponsor)));
     }
     catch (System.Exception ex) {
         throw ex;
     }
 }
Exemplo n.º 3
0
        public async Task Add_Sponsor_Test()
        {
            var sneaker = new SponsorDTO()
            {
                Name    = "Adidas",
                TeamId  = 2,
                Players = new List <int>()
            };
            string json     = JsonConvert.SerializeObject(sneaker);
            var    response = await Client.PostAsync("/api/sponsors", new StringContent(json, Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var createdSponsor = JsonConvert.DeserializeObject <SponsorDTO>(await response.Content.ReadAsStringAsync());

            Assert.NotNull(createdSponsor);
        }
Exemplo n.º 4
0
        public async ValueTask <IActionResult> Get(int id, bool projects = false)
        {
            Sponsor sponsor = null;

            if (!projects)
            {
                sponsor = await _repo.Item()
                          .Where(c => c.Id == id)
                          .FirstOrDefaultAsync();

                if (sponsor != null)
                {
                    SponsorBase model = sponsor.Convert <Sponsor, SponsorBase>(_mapper);
                    return(Ok(model));
                }
            }
            else
            {
                sponsor = await _repo.Item()
                          .Where(c => c.Id == id)
                          .Include(c => c.Projects)
                          .ThenInclude(p => p.Comments)
                          .FirstOrDefaultAsync();

                if (sponsor != null)
                {
                    SponsorDTO        model = sponsor.ConvertToDTO(_mapper);
                    SponsorProjectDTO dto   = new SponsorProjectDTO
                    {
                        Sponsor = model,
                        Total   = sponsor.Projects.Count()
                    };
                    return(Ok(dto));
                }
            }
            return(NotFound(new ErrorDTO {
                Message = "Item not found"
            }));
        }
        public async Task <SponsorDTO> AddSponsor(SponsorDTO sponsor)
        {
            try
            {
                Sponsor newSponsor = _mapper.Map <Sponsor>(sponsor);

                newSponsor.SponsorPlayers = new List <SponsorPlayer>();
                foreach (var playerid in sponsor.Players)
                {
                    newSponsor.SponsorPlayers.Add(new SponsorPlayer()
                    {
                        PlayerId = playerid
                    });
                }
                await _sponsorRepository.AddSneaker(newSponsor);

                return(sponsor);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }