public IActionResult AddDescriptionYtPreferences() { using (StreamReader stream = new StreamReader(HttpContext.Request.Body)) { Task <string> body = stream.ReadToEndAsync(); if (body.Result == "") { return(BadRequest("You must specify the user email")); } dynamic jsonBody = JObject.Parse(body.Result); string email = jsonBody.email; string description = jsonBody.description; if (!context.yt_preferences.ToList().Exists(s => s.email.Equals(email))) { YtPreference ytp = new YtPreference { email = email, description = description }; try { context.yt_preferences.Add(ytp); } catch (Exception ex) { return(BadRequest(ex)); } } else { YtPreference ytp = context.yt_preferences.First(s => s.email.Equals(email)); ytp.description = description; context.Update(ytp); } try { context.SaveChanges(); } catch (Exception ex) { return(BadRequest(ex)); } return(Ok()); } }
public IActionResult FuturePosts(int id) { try { var post = context.posts.Where(p => p.id == id).First(); // delete job linked with post var cmdTextPost = "DELETE FROM job WHERE id=@id"; var idParam = new MySqlParameter("@id", post.postId); context.Database.ExecuteSqlRaw(cmdTextPost, idParam); context.posts.Remove(post); context.SaveChanges(); return(Ok(post)); } catch (Exception ex) { return(BadRequest(ex)); } }
public IActionResult DeleteAccount(string email) { try { // delete account_emailaddress var cmdText = "DELETE FROM account_emailaddress WHERE email=@email"; var emailParam = new MySqlParameter("@email", email); context.Database.ExecuteSqlRaw(cmdText, emailParam); // delete auth_user var cmdText2 = "DELETE FROM auth_user WHERE email=@email"; context.Database.ExecuteSqlRaw(cmdText2, emailParam); // delete socials var socials = context.socials.Where(p => p.email == email).ToList(); foreach (var social in socials) { context.socials.Remove(social); } var posts = context.posts.Where(p => p.email == email).ToList(); // delete jobs foreach (var post in posts) { var cmdTextPost = "DELETE FROM job WHERE id=@id"; var idParam = new MySqlParameter("@id", post.postId); context.Database.ExecuteSqlRaw(cmdTextPost, idParam); } // delete posts foreach (var post in posts) { context.posts.Remove(post); } return(Ok(context.SaveChanges())); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> YoutubeUploadAsync() { using (var sr = new StreamReader(Request.Body)) { var body = await sr.ReadToEndAsync(); var location = Request.Headers["Location"]; var id = Request.Headers["Id"]; Social social; try { social = context.socials.First(s => s.socialId == id.ToString()); } catch (Exception ex) { return(BadRequest(ex)); } double scheduledFor = Double.Parse(Request.Headers["ScheduledFor"]); var post = new Post { email = social.email, type = SocialType.Youtube, scheduled = DateTime.Now + TimeSpan.FromMinutes(scheduledFor), title = "Youtube post", postId = BackgroundJob.Schedule(() => ytService.UploadVideo(social.accessToken, body, location), TimeSpan.FromMinutes(scheduledFor)) }; try { context.posts.Add(post); } catch (Exception ex) { return(BadRequest(ex)); } try { context.SaveChanges(); } catch (Exception ex) { return(BadRequest(ex)); } return(Ok(post)); } }