public async Task <AdminUserNotification> UpsertUserNotificationAsync(AdminUserNotification userNotification) { try { var updated = await svc.UpsertUserNotificationAsync(userNotification); log.LogInformation("Updated UserNotification. UserNotification:{@UserNotification}", updated); return(updated); } catch (DbException db) { log.LogError("Failed to update UserNotification. UserNotification:{@UserNotification} Code:{Code} Error:{Error}", userNotification, db.ErrorCode, db.Message); db.MapThrow(); throw; } }
public async Task <ActionResult <AdminUserNotification> > UpsertNotification(AdminUserNotification notification) { try { var updated = await manager.UpsertUserNotificationAsync(notification); return(Ok(updated)); } catch (LeafRPCException le) { return(StatusCode(le.StatusCode)); } catch (Exception ex) { log.LogError("Failed to update AdminUserNotification. AdminUserNotification:{@AdminUserNotification} Error:{Error}", notification, ex.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <AdminUserNotification> UpsertUserNotificationAsync(AdminUserNotification notification) { using (var cn = new SqlConnection(opts.ConnectionString)) { await cn.OpenAsync(); var updated = await cn.QueryFirstOrDefaultAsync <AdminUserNotification>( Sql.UpsertNotification, new { user = user.UUID, id = notification.Id, message = notification.Message, until = notification.Until }, commandType : CommandType.StoredProcedure, commandTimeout : opts.DefaultTimeout); return(updated); } }