public async Task <IActionResult> DisableInstapage( CancellationToken cancellationToken, [FromRoute] string login, [FromServices] Domain.Instapage.IInstapageRepository instapageRepository) { var instapage = await instapageRepository.GetByInstagram(login, cancellationToken); if (instapage == null) { return(NotFound()); } if (instapage.UserId != User.GetId()) { return(NotFound()); } try { instapage.Disable(); } catch (InvalidOperationException ex) { return(UnprocessableEntity(ex.Message)); } await instapageRepository.Save(instapage); return(NoContent()); }
public async Task <IActionResult> FbAuthentication( CancellationToken cancellationToken, [FromForm] FbAuthenticationBinding fbBinding, [FromServices] Infrastructure.Instagram.InstapageCreationService creationService, [FromServices] Domain.Instapage.IInstapageRepository instapageRepository) { try { var instapage = await creationService.CreateInstapage(User.GetId(), fbBinding.Code, cancellationToken); var instapageExists = await instapageRepository.GetByInstagram(instapage.InstagramLogin, cancellationToken); if (instapageExists != null) { return(Conflict()); } await instapageRepository.Save(instapage); return(Ok(new InstapageView { Login = instapage.InstagramLogin })); } catch (Infrastructure.Instagram.ApiException ex) { return(BadRequest(new ErrorView(ErrorCode.InstagramException, ex.Reason))); } }
public async Task <IActionResult> CreateInstapage( CancellationToken cancellationToken, [FromRoute] string login, [FromBody] CreateInstapageBinding binding, [FromServices] Domain.Instapage.IInstapageRepository instapageRepository, [FromServices] Infrastructure.Instagram.InstapageCreationService creationService) { var instapage = await instapageRepository.GetByInstagram(login, cancellationToken); if (instapage == null) { return(NotFound()); } if (instapage.UserId != User.GetId()) { return(NotFound()); } instapage.SetInfo(binding.Title, binding.Description, binding.Vkontakte, binding.Telegram); try { foreach (var instapost in binding.Posts) { if (instapage.Instaposts.Any(o => o.Id == instapost.Id)) { continue; } await creationService.SaveMedia(instapage.AccessToken, instapage.InstagramLogin, instapost.Id, cancellationToken); instapage.AddPost(new Domain.Instapage.Instapost( id: instapost.Id, instapageId: instapage.Id, title: instapost.Title, description: instapost.Description, price: instapost.Price, currency: instapost.Currency, timestamp: instapost.Timestamp)); } await instapageRepository.Save(instapage); return(NoContent()); } catch (Infrastructure.Instagram.ApiException ex) { return(BadRequest(new ErrorView(ErrorCode.InstagramException, ex.Reason))); } }