Exemplo n.º 1
0
        public ActionResult Create(
            [FromRoute] string version,
            [FromRoute] long adId,
            [FromBody] CreateAdChannel adChannel)
        {
            var channel = _context.Channels.FirstOrDefault(a => a.Id == adChannel.Channel.Id);
            var ad      = _context.Ads.FirstOrDefault(a => a.Id == adId);

            if (channel == null || ad == null)
            {
                return(NotFound());
            }
            var created = _context.AdChannels.Add(new AdChannel
            {
                Name    = adChannel.Name,
                Channel = channel,
                Ad      = ad
            });
            var result = new AdChannelRepresentation
            {
                Id        = created.Entity.Id,
                Name      = adChannel.Name,
                AdId      = ad.Id,
                ChannelId = channel.Id
            };

            _context.SaveChanges();
            return(CreatedAtAction("GetChannel", new { adId, id = created.Entity.Id, version }, result));
        }
Exemplo n.º 2
0
        public StatusCodeResult Update(
            [FromRoute] long adId,
            [FromRoute] long id,
            [FromBody] AdChannelRepresentation channel)
        {
            var adChannel = _context.AdChannels.FirstOrDefault(a => a.Id == id && a.AdId == adId);

            if (adChannel == null)
            {
                return(NotFound());
            }
            adChannel.Name = channel.Name;
            _context.AdChannels.Update(adChannel);
            _context.SaveChanges();
            return(Ok());
        }