public async Task AddTokenToDb(string tokenValue) { using (var _db = new MoMoFirebaseDbContext()) { var existingToken = await _db.FCMTokens.FirstOrDefaultAsync(t => t.FcmTokenValue.Equals(tokenValue)); if (existingToken == null) { FCMToken newData = new FCMToken() { FcmTokenValue = tokenValue, Active = true, CreatedUtc = DateTime.UtcNow, DeviceType = "WebBrowser" }; _db.FCMTokens.Add(newData); } else { existingToken.ModifiedUtc = DateTime.UtcNow; existingToken.Active = true; } await _db.SaveChangesAsync(); } }
public IHttpActionResult PostRegisterFCMToken(string id, FCMToken fcm) { if (fcm.token != "" || fcm.token != null) { var data = db.tblBiddersInfoes.Where(b => b.BiddersId == id).FirstOrDefault(); data.FCMToken = fcm.token; db.SaveChanges(); return(Json(1)); } else { return(Json(0)); } }
public ResultBase CreateToken([FromBody] FCMToken tokenData) { logger.LogInformation(JsonConvert.SerializeObject(tokenData)); var user = userService.GetUser(HttpContext.User.Claims.Where(s => s.Type == "id").FirstOrDefault().Value); if (Converters.ConvertLong(user.UserId) > 0) { Model.FCMTokenModel modelData = new Model.FCMTokenModel(); modelData.UserId = user.UserId; modelData.CompanyId = user.CompanyId; modelData.BranchId = user.BranchId; modelData.FCMToken = tokenData.TokenId; var result = FCMService.SaveFCMTokenUser(modelData); string message = string.Empty; if (result) { message = "Success"; } else { message = "Failure"; } return(new ResultBase { Status = result, Message = message, }); } else { return(new ResultBase { Status = false, Message = "User Id is empty", }); } }