コード例 #1
0
        public async Task <ActionResult <SubtitleVM> > UpdateSubtitle(int id, SubtitleVM subtitleVM)
        {
            try
            {
                if (id != subtitleVM.Subtitle.Id)
                {
                    return(BadRequest("Subtitle ID mismatch"));
                }

                var subtitleToUpdate = await subtitleRepository.GetSubtitle(id);

                if (subtitleToUpdate == null)
                {
                    return(NotFound($"Subtitle with Id = {id} not found"));
                }

                await subtitleRepository.UpdateSubtitle(subtitleVM);

                return(CreatedAtAction(nameof(GetSubtitle), new { id = subtitleVM.Subtitle.Id }, subtitleVM));
            }

            catch (DbUpdateException Ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  Ex.InnerException.Message));
            }
        }
コード例 #2
0
        public async Task <SubtitleVM> GetSubtitle(int id)
        {
            SubtitleVM subtitleVM = new SubtitleVM();

            subtitleVM.Subtitle = await appDbContext.Subtitles.FirstOrDefaultAsync(e => e.Id == id);

            return(subtitleVM);
        }
コード例 #3
0
        public async Task <SubtitleVM> CreateSubtitle(SubtitleVM subtitleVM)
        {
            var result = await appDbContext.Subtitles.AddAsync(subtitleVM.Subtitle);

            await appDbContext.SaveChangesAsync();

            subtitleVM.Subtitle = result.Entity;
            return(subtitleVM);
        }
コード例 #4
0
        private async Task <SubtitleVM> CheckDeserialize(HttpResponseWrapper <SubtitleVM> httpResponseWrapper)
        {
            SubtitleVM subtitleVM = new SubtitleVM();

            if (httpResponseWrapper.Success)
            {
                subtitleVM = await Deserialize <SubtitleVM>(httpResponseWrapper.HttpResponseMessage, defaultJsonSerializerOptions);
            }
            else
            {
                subtitleVM.Exception = await httpResponseWrapper.GetBody();
            }

            return(subtitleVM);
        }
コード例 #5
0
        public async Task <ActionResult <SubtitleVM> > CreateSubtitle(SubtitleVM subtitleVM)
        {
            try
            {
                if (subtitleVM == null)
                {
                    return(BadRequest());
                }

                await subtitleRepository.CreateSubtitle(subtitleVM);

                return(CreatedAtAction(nameof(GetSubtitle),
                                       new { id = subtitleVM.Subtitle.Id }, subtitleVM));
            }
            catch (DbUpdateException Ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  Ex.InnerException.Message));
            }
        }
コード例 #6
0
        public async Task <SubtitleVM> UpdateSubtitle(SubtitleVM subtitleVM)
        {
            Subtitle result = await appDbContext.Subtitles
                              .FirstOrDefaultAsync(e => e.Id == subtitleVM.Subtitle.Id);

            if (result != null)
            {
                appDbContext.Entry(result).State = EntityState.Detached;
                result = mapper.Map(subtitleVM.Subtitle, result);
                appDbContext.Entry(result).State = EntityState.Modified;

                await appDbContext.SaveChangesAsync();

                return(new SubtitleVM {
                    Subtitle = result
                });
            }

            return(null);
        }
コード例 #7
0
        public async Task <SubtitleVM> UpdateSubtitle(int id, SubtitleVM subtitleVM)
        {
            var response = await httpService.Put($"{url}/{id}", subtitleVM);

            return(await CheckDeserialize(response));
        }
コード例 #8
0
        public async Task <SubtitleVM> CreateSubtitle(SubtitleVM subtitleVM)
        {
            var response = await httpService.PostAsync(url, subtitleVM);

            return(await CheckDeserialize(response));
        }