public async ValueTask <bool> AddNewStringAsync(FetcherDataModel model, int userId) { var user = await Users .Include(x => x.Fetcher) .FirstOrDefaultAsync(x => x.UserId == userId); if (user == null) { return(false); } if (user.Fetcher == null) { user.Fetcher = new Fetcher(); } user.Fetcher.FetcherDataList.Add(new FetcherData() { Data = model.Data }); try { await SaveChangesAsync(); } catch (Exception ex) { Console.WriteLine(ex); return(false); } return(true); }
public async Task <IActionResult> SaveString([FromBody] FetcherDataModel fetcherReq) { if (!User.Identity.IsAuthenticated) { return(BadRequest("Need auth before the add new line")); } if (String.IsNullOrEmpty(fetcherReq.Data)) { return(BadRequest("Content is empty")); } await _fetcher.AddNewStringAsync(fetcherReq, User.GetUserId()); return(Ok("Success")); }