public ActionResult GetSubtitle(int id) { try { SubtitleDTO sbt = new SubtitleDTO(); using (MABRUKLISTEntities dbcontext = new MABRUKLISTEntities()) { var SubT = dbcontext.mblist_subtitle.Find(id); if (SubT != null) { sbt.id = SubT.subtitle_key; sbt.subtitle = SubT.subtitle_name; return(PartialView("_AddSubtitle", sbt)); } else { return(Json(new { key = false, value = "Subtitle not Found its Deleted from data base!!" }, JsonRequestBehavior.AllowGet)); } } } catch (Exception) { return(Json(new { key = false, value = "Unable to edit the Subtitle" }, JsonRequestBehavior.AllowGet)); } }
public Task <Subtitle> Create(SubtitleDTO subtitleDTO, Guid identityID) { var user = _unitOfWork.Users.GetByIdentityID(identityID); if (user == null) { _logger.Emit(ELoggingEvent.UserDoesntExist, new { UserIdentityID = identityID }); throw new ArgumentException(nameof(identityID)); } var episode = _unitOfWork.Episodes.GetByAnimeSlugAndNumber(subtitleDTO.AnimeSlug, subtitleDTO.EpisodeNumber); if (episode == null) { _logger.Emit(ELoggingEvent.EpisodeDoesntExist, new { subtitleDTO.AnimeSlug, subtitleDTO.EpisodeNumber }); throw new ArgumentException(nameof(subtitleDTO.EpisodeNumber)); } var fansub = _unitOfWork.Fansubs.GetByAcronym(subtitleDTO.FansubAcronym); if (fansub == null) { _logger.Emit(ELoggingEvent.FansubDoesNotExist, new { subtitleDTO.FansubAcronym }); throw new ArgumentException(nameof(subtitleDTO.FansubAcronym)); } if (!fansub.Memberships.Any(m => m.UserID == user.ID)) { _logger.Emit(ELoggingEvent.UserDoesntBelongOnFansub, new { subtitleDTO.FansubAcronym }); throw new ArgumentException(ExceptionMessage.UserDoesntBelongOnFansub); } return(CreateInternal(subtitleDTO, identityID, episode, fansub, user)); }
public async Task <IActionResult> DeleteSubtitle(int id) { if (id <= 0) { return(NotFound(new { status = StatusCodes.Status404NotFound, message = $"Id:{id} of Subtitle record is not correct." })); } try { Subtitle subtitle = await Task.Run(() => _subtitleService.DeleteSubtitle(id)); SubtitleDTO subtitleDTO = _mapper.Map <SubtitleDTO>(subtitle); return(Ok(new { status = StatusCodes.Status200OK, message = $"Id:<{id}> => Subtitle record is deleted.", data = subtitleDTO })); } catch (Exception ex) { return(NotFound(new { status = StatusCodes.Status404NotFound, message = ex.Message })); } }
public async Task <IActionResult> PostParse([FromBody] SubtitleDTO subtitleDto) { if (!ModelState.IsValid || subtitleDto == null) { return(BadRequest(BaseStatusDto.CreateErrorDto("SubtitleDTO request object is not correct."))); } try { Subtitle subtitle = _mapper.Map <Subtitle>(subtitleDto); if (subtitle == null) { throw new NullReferenceException("AutoMapper with SubtitleDTO=>Subtitle failed."); } await Task.Run(() => _subtitleService.ParseSubtitle(subtitle)); return(Ok(BaseStatusDto.CreateSuccessDto("Subtitle parsing operation is successful."))); } catch (Exception ex) { _logger.Debug($"{ex.GetType()} exception is generated."); _logger.Debug($"{ex.Message}"); return(BadRequest(BaseStatusDto.CreateErrorDto(ex.Message))); } }
public async Task <IActionResult> AddSubtitle([FromBody] SubtitleDTO subtitleDto) { if (!ModelState.IsValid || subtitleDto == null) { return(BadRequest(BaseStatusDto.CreateErrorDto("ModelState is not valid or the SubtitleDTO object is null."))); } try { Subtitle subtitle = _mapper.Map <Subtitle>(subtitleDto); await Task.Run(() => _subtitleService.AddSubtitle(subtitle)); subtitleDto.CreateSuccess("Subtitle record is created successfully."); return(Ok(subtitleDto)); } catch (Exception ex) { _logger.Debug($"{ex.GetType()} exception is generated."); _logger.Debug($"{ex.Message}"); return(BadRequest(BaseStatusDto.CreateErrorDto(ex.Message))); } }
public async Task <IActionResult> CreateSubtitle([FromForm] SubtitleDTO subtitleDTO) { var identityID = User.GetIdentityID(); var subtitle = await _subtitleService.Create(subtitleDTO, identityID); return(Ok(subtitle)); }
public ActionResult AddOrUpdateSubtitle(SubtitleDTO dto) { try { if (ModelState.IsValid) { using (MABRUKLISTEntities dbcontext = new MABRUKLISTEntities()) { if (dto.id == 0) { var data = dbcontext.mblist_subtitle.Where(x => x.subtitle_name == dto.subtitle).FirstOrDefault(); if (data != null) { return(Json(new { key = false, value = "Subtitle already exist" }, JsonRequestBehavior.AllowGet)); } else { mblist_subtitle sbtitle = new mblist_subtitle() { subtitle_name = dto.subtitle }; dbcontext.mblist_subtitle.Add(sbtitle); dbcontext.SaveChanges(); return(Json(new { key = true, value = "Subtitle added successfully" }, JsonRequestBehavior.AllowGet)); } } else { var data = dbcontext.mblist_subtitle.Find(dto.id); if (data != null) { data.subtitle_name = dto.subtitle; dbcontext.SaveChanges(); return(Json(new { key = true, value = "Subtitle updated successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { key = false, value = "Subtitle not found" }, JsonRequestBehavior.AllowGet)); } } }; } else { return(Json(new { key = false, value = "Please enter correct data" }, JsonRequestBehavior.AllowGet)); } } catch (Exception) { return(Json(new { key = false, value = "Unable to save the Subtitle" }, JsonRequestBehavior.AllowGet));; } }
public async Task <IActionResult> GetSubtitleById([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(BaseStatusDto.CreateErrorDto("Id of subtitle is incorrect."))); } Subtitle subtitle = _subtitleService.GetSubtitleById(id); if (subtitle == null) { return(BadRequest(BaseStatusDto.CreateErrorDto($"There is no a Subtitle record with Id = {id} in the Subtitles table."))); } SubtitleDTO subtitleDTO = _mapper.Map <SubtitleDTO>(subtitle); subtitleDTO.CreateSuccess("GET request by Subtitle Id succeeds."); return(Ok(subtitleDTO)); }
public async Task <IActionResult> GetSubtitleByPath([FromBody] string path) { if (!ModelState.IsValid || string.IsNullOrEmpty(path)) { return(BadRequest(BaseStatusDto.CreateErrorDto("The Path of the subtitle is incorrect."))); } Subtitle subtitle = _subtitleService.GetSubtitleByPath(path);//GetSubtitleByPath(path); if (subtitle == null) { return(BadRequest(BaseStatusDto.CreateErrorDto( $"There is no any Subtitle record with Path = {path} in the Subtitles table."))); } SubtitleDTO subtitleDTO = _mapper.Map <SubtitleDTO>(subtitle); subtitleDTO.CreateSuccess("GET request by Subtitle Path succeeds."); return(Ok(subtitleDTO)); }
private async Task <Subtitle> CreateInternal(SubtitleDTO subtitleDTO, Guid identityID, Episode episode, Fansub fansub, User user) { var subtitle = _unitOfWork.Subtitles.Create(new Subtitle { EpisodeID = episode.ID, FansubID = fansub.ID, Status = subtitleDTO.Status, Format = subtitleDTO.Subtitle.GetSubtitleFormat(), }); var subtitlePartial = _unitOfWork.SubtitlePartials.Create(new SubtitlePartial { UserID = user.ID, SubtitleID = subtitle.ID, }); _unitOfWork.Save(); string subtitleUrl; try { subtitleUrl = await _unitOfWork.Storage.UploadSubtitle(subtitleDTO.Subtitle, fansub.ID, subtitle.ID); } catch (Exception ex) { // TODO: AZ to do this cleaning instead of on the call _logger.Emit( ELoggingEvent.CantUploadSubtitle, new { subtitleDTO.AnimeSlug, subtitleDTO.EpisodeNumber, UserIdentityID = identityID, Exception = ex, } ); _unitOfWork.Subtitles.Delete(subtitle); _unitOfWork.SubtitlePartials.Delete(subtitlePartial); _unitOfWork.Save(); throw; } string subtitlePartialUrl; try { subtitlePartialUrl = await _unitOfWork.Storage.UploadSubtitlePartial(subtitleDTO.Subtitle, fansub.ID, subtitle.ID, subtitlePartial.ID); } catch (Exception ex) { // TODO: AZ to do this cleaning instead of on the call _logger.Emit( ELoggingEvent.CantUploadSubtitlePartial, new { subtitleDTO.AnimeSlug, subtitleDTO.EpisodeNumber, UserIdentityID = identityID, Exception = ex, } ); _unitOfWork.Subtitles.Delete(subtitle); _unitOfWork.SubtitlePartials.Delete(subtitlePartial); _unitOfWork.Save(); _unitOfWork.Storage.DeleteSubtitle(fansub.ID, subtitle.ID); throw; } try { subtitle.Url = subtitleUrl; subtitlePartial.Url = subtitlePartialUrl; _unitOfWork.Save(); } catch (Exception ex) { // TODO: AZ to do this cleaning instead of on the call _logger.Emit( ELoggingEvent.CantLinkSubtitleUrl, new { subtitleDTO.AnimeSlug, subtitleDTO.EpisodeNumber, UserIdentityID = identityID, Exception = ex, } ); _unitOfWork.Subtitles.Delete(subtitle); _unitOfWork.SubtitlePartials.Delete(subtitlePartial); _unitOfWork.Save(); _unitOfWork.Storage.DeleteSubtitle(fansub.ID, subtitle.ID); _unitOfWork.Storage.DeleteSubtitlePartial(fansub.ID, subtitle.ID, subtitlePartial.ID); throw; } return(subtitle); }
public ActionResult AddSubtitle() { SubtitleDTO SBtitle = new SubtitleDTO(); return(PartialView("_AddSubtitle", SBtitle)); }