public async Task <IActionResult> PutPodcastEpisode([FromQuery] int id, [FromBody] PodcastEpisode podcastEpisode)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != podcastEpisode.Id)
            {
                return(BadRequest());
            }

            _context.Entry(podcastEpisode).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PodcastEpisodeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <IActionResult> PutFollowedPodcast([FromQuery] string rss, [FromBody] FollowedPodcast followedPodcast)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (rss != followedPodcast.Rss)
            {
                return(BadRequest());
            }

            _context.Entry(followedPodcast).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FollowedPodcastExists(rss))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public async Task <IActionResult> Register([FromBody] PodUser podUser)
        {
            using (var db = new PodTrackdbContext())
            {
                if (db.PodUser.FirstOrDefault(x => x.Username == podUser.Username) != null)
                {
                    return(BadRequest(new { message = "Username already exists." }));
                }

                podUser.Password = PasswordStorage.CreateHash(podUser.Password);

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                db.PodUser.Add(podUser);
                await db.SaveChangesAsync();

                return(Ok());
            }
        }