/*TEST Get all notification token from Expo react in order to send notification to user*/ public List <ExpoToken> GetNotiToken() { try { var list = _dbContext.accounts.ToList(); //get all user account List <ExpoToken> expolist = new List <ExpoToken>(); //loop for forming new form in order to return to dev foreach (var run in list) { ExpoToken expoToken = new ExpoToken() { Id_account = run.Id_account, Expotoken = run.ExpoToken }; expolist.Add(expoToken); } //if there is no any account if (expolist.Count() == 0) { return(null); } //if there is account else { return(expolist); } } catch (Exception) { //error return(null); } }
public IActionResult NotiToken([FromBody] ExpoToken notiToken) { TimeZoneInfo zone = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time"); DateTime dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone); // if it can add notification token if (_accountRepo.NotiToken(notiToken)) { Log.Information("Add notification token {Id} OK. {DateTime}.", notiToken.Id_account, dateTime); return(Ok(notiToken.Id_account)); } // if it can not add notification token Log.Information("Add notification token {id} Error. {DateTime}.", notiToken.Id_account, dateTime); return(NotFound("Error to add notification token")); }
public async Task <ActionResult <ExpoToken> > PostExpoToken([FromBody] ExpoToken expoToken) { ExpoToken token = await _context.ExpoTokens.Where(f => f.Token == expoToken.Token).FirstOrDefaultAsync(); if (token == null) { _context.ExpoTokens.Add(expoToken); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetExpoTokenByToken), new { token = expoToken.Token }, expoToken)); } else { return(Ok()); } }
/* Store notification token from Expo react in order to send notification to user*/ public bool NotiToken(ExpoToken _token) { try { //if there is user account in the database if (_dbContext.accounts.FirstOrDefault(x => x.Id_account == _token.Id_account) != null) { _dbContext.accounts.FirstOrDefault(x => x.Id_account == _token.Id_account).ExpoToken = _token.Expotoken; } //if there is no user account in the database else { return(false); } _dbContext.SaveChanges(); return(true); } catch (Exception) { //error Console.WriteLine("Cannot add notitoken"); return(false); } }